I want to write a program, which creates RDBMS-tables through JDBC automatically. To add columns to a table, I need to know the name of the column and the column's RDBMS datatype. I already have the names of the columns. I don't have the RDBMS types for the columns, but I have Java types for those column. So I need to map those Java types to RDBMS datatypes. The Java type can be one of the following:
String
So my question is: How to map those java types to RDBMS types?
Especially I am working with PostgreSQL. So if there is no genenic way to do it, it would be important for the moment to get it running with PG.
Thanks in advance
In Derby, the java. sql. Types are mapped to SQL data types.
STEP 1: Allocate a Connection object, for connecting to the database server. STEP 2: Allocate a Statement object, under the Connection created earlier, for holding a SQL command. STEP 3: Write a SQL query and execute the query, via the Statement and Connection created. STEP 4: Process the query result.
Blob is the mapping for the SQL BLOB (binary large object) type; java. sql. Clob is the mapping for the SQL CLOB (character large object) type. BLOB and CLOB objects are collectively referred to as LOBs (large objects).
The Java String and byte[ ] datatypes correspond to SQL varchar and varbinary, where the maximum length value of 16K bytes is defined by Adaptive Server.
Well, there there's always the java.sql.Types class which contains the generic SQL type mappings, but you'd be better served using something like Hibernate to do all of this for you.
getTypeInfo() is intended to get the driver's view on which (native) DBMS type should be mapped to which JDBC type. But these mappings aren't always precise so you will need to find some way of detecting the "best match"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With