aspose file tools*
The moose likes JDBC and the fly likes Database URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database URL" Watch "Database URL" New topic
Author

Database URL

Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Hi,
I'm trying to access MS SQL Server Database using Java application and JDBC.
I have created System DSN "JDBCTest" using 32 bit ODBC Administrator.
I would like know if the following syntax for database URL is correct :
String dbURL = "jdbc:0dbc:JDBCTest"
Thanks
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Hi,
Getting error when I run the following code java.sql.SQLException: [Microsoft][ODBC Driver Manager]Invalid Cursor State
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:4089)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:4246)
import java.sql.*;
public class Lookup {
public static void main(String args[]) {
String dbURL = "jdbc dbc:JDBCTest";
String user = "dbo";
String password = "dbo";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection(dbURL,user,password);
Statement s = c.createStatement();
ResultSet r = s.executeQuery("select user_id from tuser where user_last_nm = 'kalyankar'");
System.out.println(r.getString("user_id"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
What could be the problem ?
Thanks
[This message has been edited by Dilipkumar Kalyankar (edited October 19, 2000).]
[This message has been edited by Dilipkumar Kalyankar (edited October 19, 2000).]
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
Try adding exception logic whn registering your driver...
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
Look withn this form for complete java/odbc code examples.
I have posted a few... search for 'monty6'
Hope this Helps.

------------------
We learn more from our mistake's than from our success's.


Multi Platform Database Developer & DBA on E.S.T.
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Monty,
After replacing
System.out.println(r.getString("user_id"));
with
while (r.next()) {
System.out.println(r.getString("user_id"));
}
it worked.
Thanks
[This message has been edited by Dilipkumar Kalyankar (edited October 20, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database URL
 
Similar Threads
how to create database in ms-sql server using java/jdbc
java.sql.SQLException: No suitable driver
No suitable driver found
No suitable driver using msql
Can I store objects