thomasokken / jdbcnav

JDBC Navigator
https://thomasokken.com/jdbcnav/
GNU General Public License v2.0
0 stars 1 forks source link

Launch via command line arguments #1

Open maxandersen opened 4 days ago

maxandersen commented 4 days ago

It would be great if could pass connection info via command line.

So I could do: jbang --deps driverdeps jdbcnavjarurl.jar -u dummy -p secret --url jdbc://...

Could also add driverdeps as a command line arguments.

thomasokken commented 3 days ago

One drawback of using command line arguments is that the password will be visible to anyone, at least on Unix-like systems where you can do ps -ef or similar. Another possibility would be to provide the connection info in a file, and then specify the filename on the command line; the app could delete the file once it's finished reading it. Or the info could be sent to standard input, on systems that support that.

thomasokken commented 3 days ago

The mechanics of opening the connection look straightforward. Create an instance of JDBCDatabase.LoginDialog.ConnectThread with the given driver class name, JDBC URL, username, and password, and then run it. It will require some surgery to do that without having an actual LoginDialog, and to make sure it runs after everything else has been initialized, but that's not rocket science.

maxandersen commented 3 days ago

sure - can add additional security efforts; or if password not specified prompt user for that piece.

my main usecase is to connect to local running dev databases anyway so less concerned about password being exposed this way.

thomasokken commented 1 day ago

I'm starting out with command line options; once I'm satisfied that's working well, I'll add the option to read connection configs from a file as well.

What I'm working on now are options like this: -driver=X, -url=X, -user=X, -pass=X, and -name=X. Only -driver and -url are required. If -user and/or -pass are omitted, they are set to "" (empty string); if -name is omitted, it is set to "cmdline.<n>". The name is what's shown as the window title for the connection.

It is possible to specify multiple connections, by adding ".<n>" to the options: -driver.2=Y, -url.2=Y, etc. If there is no number, it is assumed to be 1.

I've written most of the code, but it still needs some work, mostly better error reporting and testing. If you like, I'll upload a test version once the code is in a satisfactory state.

maxandersen commented 8 hours ago

@thomasokken happy to look at PR and build/test from there

thomasokken commented 8 hours ago

You can just check out master and build that. It supports the command-line options as I described before, and survived a few basic tests. I'll add error reporting, and support for config files, over the weekend.

maxandersen commented 6 hours ago

checked it out but had to change 1.7 to 1.8 in build.xml.

I got it working, but a few comments:

1) should it not be --driver=... instead of -driver=... double dash instead of single? 2) it seems driver is required, normally jdbc figures out driver name from classpath when jdbc URL is available. could it be optional ? 3) username/password seems to be required too but should be optional as can be specified in some jdbc URLs thus should be optional 4) nothing is printed when things are bad/missing. Would be nice to get hint if something missing/parse error 5) would be great with a --help option.

thomasokken commented 5 hours ago
  1. In order for DriverManager to find a driver, it has to be registered first. That's accomplished by calling Class.forName(driverClassName); this causes the driver's class initializer to register itself. It's not sufficient for the driver's jar file to merely exist in the class path. Or at least that's how it used to work when I first started working on this app; if that's no longer true, then that would indeed simplify the code a bit.
  2. username/password are optional.
  3. Indeed! That's why I mentioned I still need to implement error reporting.