Monday, October 29, 2018

Incorporating H2 database into Eclipse

So I finally did this.

Here's a decent explanation.

https://ibytecode.com/blog/eclipse-dtp-configure-h2-datasource-using-data-source-explorer/

but it goes wrong at the end.

(This is for Eclipse Oxygen; Eclipse Mars can't even do this, on my machine at home; Eclipse Luna doesn't do it either. This is curious, it doesn't feel like a new thing.)


Here's much the same thing over again:

Menubar File->New->Other...

Good god. My pasted-in pictures all got lost. Yeesh. Gotta do them over, saved as files. Yeesh.




Choose "Connection Profile" and "Next"

See this: and click Generic JDBC




Type "H2 JDBC" for the name. (When you try to do this again, you can't use the same name, you'll get told it exists). Click "NEXT", and get a new dialog window.

Click on the strange icon inside the red circle:




See this new dialog:




Click on Generic Driver. Enter H2 JDBC Driver for the name.


If you don't click on Generic, you can't do the next thing:




which is click on "Add JAR". Find your H2 jar file.



Now comes the absurd part. Click on the H2 jar file name. Click on Properties tab button. It's blank. Go back to JAR list. Click the jar file. Click Properties. Still blank. Back to JAR list. Click the H2 file name.

The Edit button will now be active. Click that, the click Cancel in the file dialog. Now click Properties. Yay! props table.


Driver class is org.h2.Driver (capitalized just that way). URL is jdbc:h2:tcp://localhost/wherever-your-db-is. Name is whatever you want as a name. I'm not sure what this is for. Click OK.



enter a password, click "save", click "test connection" to be sure you don't have a typo somewhere.

The tab for "Optional" parameters would be something like mvstore=false; or other jazz.

I don't recommend turning on "connect every time". Regrettably, you'll have to go through this again every time you have a new database, but the end result here is that you can create a .sql file in a project, and connect it to this database, and run sql live right there from in the buffer.



I should have done this years ago...but Eclipse is not really the best of all possible interfaces to H2. Especially since it won't show the result from "SELECT * FROM my_table;", just whether or not it executed error-free.

I have some other tools I wrote for real database interface work, but they don't do text-edit buffer.

--------------------------------

Of course, H2 already has to have that database created...I was trying to get a CSV dumped into a single table to practice some SQL with. Just the load was trickier than I wanted.

How to load a table from CSV into H2:



(Yep, I'm looking at some FCC data.)

H2 doesn't give a very good explanation for CSVREAD to load a DB. Tried it before, and spent an hour today trying to guess what it wanted for syntax. It's actually really simple, simpler than it looks in their doc.

INSERT INTO table(col, col,col...) SELECT col,col,col... FROM csvread("file-location.csv");

There's a simpler way if your table will have exactly the same columns as the CSV, but mine had that extra "ID" column first.

Tuesday, October 09, 2018

Even supposed whiz-kids get it wrong


So I needed to try to export Contacts info in OSX High Sierra to a CSV file. Sounds simple enough, right? If *I* had written the Contacts app, this would be a direct thing off the file menu.

Apple, however, in its infinite wisdom, has completely failed on this. You cannot. Full stop.

You should NOT need an Advanced Degree (tm) to figure this out. But apparently you do.


OK, that said, there is a way, but it's really stupid to have to do it. OK, there might be two. I only tried one.

You have to open Contacts, figure out how to "Select All" (or whatever subset you like), then you open Numbers (yes, Numbers), and click/hold/drag that bunch of contacts over into Numbers (and not just anywhere, you have to land on the actual cells grid. Then you wait a few moments, and poof, the cells are filled with your data. 

From Numbers, you can then do a CSV save. Ye Gods.

That is pointlessly over-complex. CSV is a basic output flavor for contact info--even if you don't look at it in a table (come to think of it, why is THAT not an option? What happens when I need to look at two at once?), it's a table, and. you can always output a table as CSV.

Especially when most things that import tabular data want either a CSV or XLS. Like something I'd need to dump contacts info into.

-----

Looks like Automator might be able to do it. And there maybe is an app in the Store that reads the regular abbu export and makes a CSV. 

Seriously?