Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

SQL Server nvarchar and JDBC

843854Aug 11 2004 — edited Nov 8 2004
Hi to all,
My DBMS is SQL Server2000 and i created a table which has two columns. Two of them were defined as varchar, but when i wrote Turkish character, these characters automaticly were converted to the different characters. Because varchar does not support Unicode. So, I had to use nvarchar, but if i used nvarchar how can I match nvarchar values to the java.sql.Types. There is no matching values for SQL Server nvarchar type. So, that is my question, how can i write Turkish character to the SQL Server via application which uses JDBC API to connect to the SQL Server.

Regards
Bulent

Comments

843854
Hi I am curious to see how you established a JDBC connection using Java to SQL Server 2000.

Can you provide some code as an example for me?

I am having problems just establishing a connection. I downloaded the JDBC driver from MS site and installed it.

Here is some code I got:
--------------------------------------------------------------------------------
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://DEV01:1433;DatabaseName=NG_RFQ;SelectMethod=cursor", "jla", "jla");

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Customer");

if(rs.next()){

customerName = rs.getString("CustomerName");
buyerName = rs.getString("BuyerName");

}

con.close();
---------------------------------------------------------------------------------------

Can you tell me what I am doing wrong? Do I need to create a new DSN or something? I have no idea.

Please advise.
Thanks!!!
843854
Hi,
I did not use MS SQL Server JDBC driver, because it has lots of bugs. So I prefer you to use MS ODBC driver, it is better.

for driver "sun.jdbc.odbc.JdbcOdbcDriver"
for url "jdbc:odbc:CCSData" CCSData is the name ODBC data source created by you
for userid "user" you will define user id and password when creating ODBC connection.
for password "user"

Goodluck
843854
Try using java.type string, for SQL server nvarchar.
Also you will have to prefix the strings with national 'N' prefix for regular statements.

Here is a sample

driver="sun.jdbc.odbc.JdbcOdbcDriver";
CURL="jdbc:odbc:database";
un=null;
pw=null;

Connection con = DriverManager.getConnection( CURL, un, pw );
Statement stmt = con.createStatement();
String insrt="INSERT INTO myTable (myCol) VALUES (N' Here is the national text ' )";
stmt.execute(insrt);

I hope this solves your problem.
625957
I did not use MS SQL Server JDBC driver, because it
has lots of bugs. So I prefer you to use MS ODBC
driver, it is better.
I have found the microsoft jdbc driver SP3 version to be pretty solid.
I would not recommend the JDBC / ODBC bridge, actually neither do Sun:
"The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available. " - http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html





625957
Assuming you are using the microsoft driver:

The documentation says that both VARCHAR and NVARCHAR map to varchar in JDBC. No problems as all Strings are unicode in java.

Basically if you use PreparedStatements the driver adds the N before the quotes for you. Just make sure you dont set the SendStringParameters connection property to false.
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 6 2004
Added on Aug 11 2004
5 comments
275 views