• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem to connect to SQL server 7

 
Michelle Lee
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody tell me how can I connect to SQL server using JDBC.
I used the code below, but got a error message:
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
What is wrong with me?
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
con = DriverManager.getConnection( "jdbc dbc:mydatabase", user, passwd );
I register mydatabase in MS Data Source (ODBC).
and succcessfully connect the Access database with the same code and way.
What is the difference betwwn connect SQL7 database and access database?
Thank your for any help!
[ April 06, 2002: Message edited by: Mei Xiao ]
 
Murali Obla
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello mei,
The error clearly shows that something wrong the connection URL.Have u created a DSN for SQL server?.why don't u check it again.GOTO control panel->32 bit ODBC -> Add -> choose SQL Server->give the dsn name,description,click next and u have to choose a default database there and then press test connection.It will show test succees.
This is the code for connecting to sql server
Class.forName("sun.jdbc.odbc.JdbcOdbcdriver");
Connection con= DriverManager.getConnection("jdbc dbc snname");
user name and pwd are optional if u r using integrated security.
I hope this will work,Juss check the DSN name once again(add it properly)
cheers,
Murli
 
Michelle Lee
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Murli!
Actually I found later my database connection is already set up. and I can get a data from database
by nickname = rs.getString("NICK_NAME");
But when run the next statement:
rs.getInt("ID") == -1 )
it give the above error:
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
Stange enough the code run without problem when I run in access database.
Another problem I met is the tomcat4 server keep
shutdown automaticly.
Is any body know what is teh problm?
 
Murali Obla
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mei,
Instead of givin the column name directly in the rs.getString("NICK_NAME") just try to give column index ie rs.getInt(2) and rs.getString(1).
1--->for the first column in ur table
2--->2nd column (in ur case it's integer).
Hope this will work,
cheers,
Murli
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic