"Generate entities from table" (MS Access) in Eclipse via UCanAccess - java

I created a JPA project to use the tool Generate entities from Table to create an Entitie from a big big! MS Access Database Table.
I'm trying to use UCanAccess as JDBC Driver:
But when I test the connection I get this error:
Somebody knows what can I try to make it works?
Is there any other good tool to generate entities from table?
I have created a simple class to test UCanAccess and my database and everything works right.

It looks like there is something bad in your JDBC URL, e.g.:
jdbc:ucanaccess://C:/Users/Public/Database1.accdb;showSchema=true
Notice that the IDE can't know how the JDBC URL should be composed.

This seems to be working for me:

Related

How to add schema/other user to database url given to java?

I'm trying to connect a spring boot java application to an Oracle database. Oracle SQL Developer shows the tables I wish to query being in the DB named testdb under Other users -> `testUser.
I can connect to the DB using url jdbc:oracle:thin:#localhost:1521:testdb. However, when I use an SQL statement
SELECT * FROM SCHEMA_DEFINITION WHERE SCHEMA_NM = ?
Java doesn't find the table named SCHEMA_DEFINITION. Using testUser.SCHEMA_DEFINITION in the SQL statement does work. How can I tell Java to look for all the tables in Other users->testUser?
I have tried setting the datasource's schema (dataSource.setSchema("testUser");) and changing the url (adding ?search_path=testUser and ?currentSchema=testUser).
None of these work.
it's not a java issue, what you need is to log into the user testUser so you can query those tables without the verbose syntax if you really need to keep these queries as is, and run them from testdb then you need to create synonyms for those tables inside testdb schema:
CREATE SYNONYM TESTDB.SCHEMA_DEFINITION FOR testUser.SCHEMA_DEFINITION;
do this for each table and they will work.
Found the solution in github.com/embulk/embulk-input-jdbc/issues/144. dataSource.setSchema("testUser"); works if I use ojdbc7 (I was using ojdbc6 in my pom.xml).

Register custom jdbc driver in sql anywhere

Is it possible, to register some custom JDBC driver in SQL-Anywhere,
so that it is possible to embed a table as remote table so that
statements on that table are redirected to that driver? For example
if a select gets executed, i want to query data from a webservice and
return the fir the resut-set. The same things for inserts and so on.
Thank you very much!
From the Javadoc of DriverManager:
JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:
my.sql.Driver
So there's your way of defining custom JDBC drivers. As you want to not use the sql anywhere driver in your application (because you'll have your own driver inside the remote part of your setup), there's no need to integrate with sql anywhere there - that's something you have to take care of in your webservices where you'll transform the networked SQL calls to SQL Anywhere calls.
Check out VJDBC - that already does something similar to what you want to do.
Good Luck

Hibernate - Cannot create table in postgresql

I am trying to use hibernate framework with eclipse in order to build a simple web application and connect it with PostgreSQL. Here is my code:
Here is the error:
Does anyone know what I am doing wrong?
You should change property hibernate.hbmddl.auto value to create-drop or create to force hibernate create schema, because userclass table is not exists.
More information about hibernate.hbmddl.auto is here: https://stackoverflow.com/a/24417561/2055854
Just for those whom might encounter the same problem...
I just found the answer for it. Because of the database I am using is postgresql, I had to change the property "hibernate.dialect" in the persistence file. So, the result after the change was:
After that, the table was created!
Thank you.

How to see all tables in my h2 database at localhost:8082?

I use JDBC and created h2 database called usaDB from sql script. Then I filled all tables with jdbc.
The problem is that after I connect to usaDB at localhost:8082 I cannot see on the left tree
my tables. There is only INFORMATION_SCHEMA database and rootUser which I specified creating usaDB.
How to view the content of tables in my h2 database?
I tried query SELECT * FROM INFORMATION_SCHEMA.TABLES.
But it returned many table names except those I created. My snapshot:
I had the same issue and the answer seems to be really stupid: when you type your database name you shouldn't add ".h2.db" suffix, for example, if you have db file "D:\somebase.h2.db" your connection string should be like "jdbc:h2:file:/D:/somebase". In other way jdbc creates new empty database file named "somebase.h2.db.h2.db" and you see what you see: only system tables.
You can use the SHOW command:
Using this command, you can lists the schemas, tables, or the columns of a table. e.g.:
SHOW TABLES
This problem drove me around the twist and besides this page I read many (many!) others until I solved it.
My Use Case was to see how a SpringBatch project created in STS using :: Spring Boot :: (v1.3.1.RELEASE) was going to behave with the H2 database; to do the latter, I needed to be able to get the H2 console running as well to query the DB results of the batch run.
This is what I did and found out:
Created an Web project in STS using Spring Boot:
Added the following to the pom.xml of the latter:
Added a Spring configuration file as follows to the project:
This solves the Web project deficiencies in STS. If you run the project now, you can access the H2 console as follows: http://localhost:8080/console
Now create a SpringBatch project in STS as follows (the alternative method creates a different template missing most of the classes for persisting data. This method creates 2 projects: one Complete, and the other an initial. Use the Complete in the following.):
The SpringBatch project created with STS uses an in memory H2 database that it CLOSES once the application run ends; once you run it, you can see this in the logging output.
So what we need is to create a new DataSource that overrides the default that ships with the project (if you are interested, just have a look at the log messages and you will see that it uses a default datasource...this is created from:
o.s.j.d.e.EmbeddedDatabaseFactory with the following parameters:
Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa')
So, it starts an in memory, and then closes it. You have no chance of seeing the data with the H2 console; it has come and gone.
So, create a DataSource as follows:
You can of course use a properties file to map the parameters, and profiles for different DataSource instances...but I digress.
Now, make sure you set the bit that the red arrow in the picture is pointing to, to a location on your computer where a file can be persisted.
Running the SpringBatch (Complete project) you should now have a db file in that location after it runs (persisting Person data)
Run the Web project you configured previously in these steps, and you WILL :=) see your data, and all the Batch job and step run data (et voila!):
Painful but rewarding. Hope it helps you to really BOOTSTRAP :=)
I have met exactly this problem.
From what you describe, I suppose that you connect your jdbc with the "real" h2 server, but you are connecting on web application to database by the wrong mode (embedded-in-memory mode, aka h2mem). It means that h2 will create a new database in-memory, instead of using your true database stored elsewhere.
Please make sure that when you connect to this database, you use the mode Generic H2 (Server), NOTGeneric H2 (Embedded). You can refer to the picture below.
Version of jar file and installed h2 database should be same.
If in case you have created and populated H2 database table using maven dependency in spring boot, then please do change the JDBC URL as jdbc:h2:mem:testdb while connecting to H2 using web console.
It is an old question, but I came across the same problem. Eventually I found out that the default JDBC URL is pointing a test server rather than my application. After correcting it, I could access the right DB.
I tried with both Generic H2 (Embedded) and the Generic H2 (Server) options, both worked as long as the JDBC URL: is provided correctly.
In grails 4.0.1 the jdbc URL for development is jdbc:h2:mem:devDb. Check your application.yml file for the exact URL.
For the people who are using H2 in embedded(persistent mode) and want to "connect" to it from IntelliJ(other IDEs probably apply too).
Using for example jdbc url as follows: jdbc:h2:./database.h2
Note, that H2 does not allow implicit relative paths, and requires adding explicit ./
Relative paths are relative to current workdir
When you run your application, your workdir is most likely set to your project's root dir
On the other hand, IDE's workdir is most likely not your project's root
Hence, in IDE when "connecting" to your database you need to use absolute path like: jdbc:h2:/Users/me/projects/MyAwesomeProject/database.h2
For some reason IntelliJ by default also adds ;MV_STORE=false. It disables MVStore engine which in fact is currently used by default in H2.
So make sure that both your application and your IDE use the same store engine, as MVStore and PageStore have different file layouts.
Note that you cannot "connect" to your database if your application is using it because of locking. The other way around applies too.
In my case the issue was caused by the fact that I didn't set the h2 username, password in java. Unfortunatelly, Spring didn't display any errors to me, so it was not easy to figure out. Adding this lines to dataSource method helped me fix the issue:
dataSource.setUsername("sa");
dataSource.setPassword("");
Also, I should have specified the schema when creating tables in schema.sql
Selecting Generic H2 (Server) solved for me. We tempted to use default Generic H2 (Embedded) which is wrong.

Java - MySQL - Temporary Tables

I periodically receive data that I use to update my database with. The external structure differs from my internal structure so what I end up doing is running the import and then running alter table commands. I do this manually. After I format it to my liking, I export the data and then import it into my existing schema.
My questions are:
1. How can I isolate the external SQL so that it does not adversely affect my database? Ideally, I would like to run it as another user in another database / workspace. Should I create a database temporarily and then drop it once this operation is complete?
Should I connect directly using JDBC to run all these queries since there will be a large sum of data? I am using Hibernate along with C3P0 to manage the primary connection.
Lastly, is there an API to automate/simplify exporting to SQL? If I go the JDBC route, I can iterate through each row and create the insert statements from that.
Any ideas?
Thanks,
Walter
IMO, its better to do that outside of Hibernate, using simple JDBC. Just create a connection for this thing, and execute all SQL statements. In the end close the connection. This way its handy to make a connection to another temporary database, if you choose this route. You will not need to configure all that into your Hibernate configuration.
Other way is to go with Hibernate and let it create the schema for you using entity objects and their mappings. This way you don't need to manually come up with the database structure required, it will be automatically created by Hibernate.

Categories