I failed to connect with my database, it give me the massage as following;
Cannot load the SQL driver. Include it in your classpath
Could anyone tell me why? Thanks
And i am using the Microsoft SQL server 2000, Java 2 runtime enviroment and Microsoft SQL Server 2005 JDBC Driver now.
In the user varible, i set a path for the java run time as "c:\Program Files\Java\j2re1.4.2\javaws"
and CLASSPATH =.;C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.1\enu\sqljdbc.jar for the JDBC Driver.
and i also tried
1)
-classpath =.;"C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.1\enu\sqljdbc.jar"
2)i moved the file of the sqljdbc.jar to a path as c:\temp
then i try it again as following;
varible name: -classpath
value: ",;C\temp\sqljdbc.jar"
They are still not work
but it does not work
and my code as following;
public MyTest()
{
//information of our connection
//the url of the database: protocol:subprotocol:subname:computer_name:port:database_name
String strUrl = "jdbc:sqlserver://localhost;user=xx;password=xxxx";
//user name and password
String strUser = "xx";
String strPass = "xxx";
//try to load the driver
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch (ClassNotFoundException e) {
System.out.println( "Cannot load the SQL driver. Include it in your classpath.");
System.exit( -1);
}
//a null reference to a Connection object
c = null;
try {
//open a connection to the database
c = DriverManager.getConnection( strUrl);
}
catch (SQLException e) {
System.out.println("Cannot connect to the database. Here is the error:");
e.printStackTrace();
System.exit( -1);
}
//create a statement object to execute sql statements
displayInformation();
}
By the way, how i can delete a system variable?
i set the classpath for the sqljdbc in system variable section, but i want to delete it, but when i click the delete button, it does not has reaction. Do you known i i can solve this problem? ThanksCan you give me the whole string you are using to execute this. Have you tried running this with Eclipse?
No comments:
Post a Comment