This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connecting to a MS SQL database with JDBC

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Im trying to connect to a MS SQL 7.0 database using JDBC. I have found a JDBC driver that consists of 6 .class files in a .jar fil. I have placed the jar file in the same directory as the other jar files my compiler uses (c:\jdk1.3.1\jre\lib\jdbc.jar). Im writing the code in JCreator LE, and I have added the package to the list of packages that the compiler can use. I have writen the follwing code, that is based on an example found on sun's webpage (I have substituted the necessary code to fit my system):
package myprojects.testforbin;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Testforbin {
public static void main(String args[]) {
String url = "jdbc:inetdae:wwwproxy.kom.auc.dk:3128";
String createString;
createString = "SELECT * FROM Itemhist;";
Connection con;
Statement stmt;

try {
Class.forName("com.inet.tds.TdsDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print ("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
con = DriverManager.getConnection(url, "sa", "");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
This code compiles ok, but when I try to run it I get the following error messages:
"ClassNotFoundException: com.inet.tds.TdsDriver"
and
"SQLException: No suitable driver found"
The "com.inet.tds.TdsDriver" part is what the read me file that came with the driver says it is called.
Does anyone have any idea what is wrong here??
I have tried everything I can think of so any suggestion is welcome.
Regards
S�ren Augustesen
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No suitable driver - Make sure that the driver is registered and that you use a connection URL consistent with your JDBC driver. See your JDBC Driver documentation for the correct values.
as well...but not causing any problems yet:
I think your statement is trying to execute a dml command, while you are supplying it with a SQL query

or if you want to execute a DML statement, use your old code by change the createString to "Update..." or "INSERT..." or "DELETE...".
Jamie

[This message has been edited by Jamie Robertson (edited December 06, 2001).]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe try
DriverManager.registerDriver(new com.inet.tds.TdsDriver());
the url is only a guess, but you can check the docs for your driver. Is there any sample programs you can check for correct syntax? (assuming your classpath is correct) If not, try downloading the drivers again.
Jamie
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Soren,
i don know the reason why ur code is giving error but i tried to use jdbc with MS-SQL 2000 's driver's beta version and there is a bug in one of the jar file (when we try to view it or expand it, it gives us error of formatting).
so make sure that any kind of similar problem is not there with the driver. (check out MS newsgroups i guess for that. i don know the link for that tho)
regards
maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic