jdbc 连接数据库问题 报错:No suitable driver
为了测试jdbc的中文冷僻字问题 ,写了个测试程序
import java.sql.*;
import java.io.*;
import java.lang.*;
import java.text.SimpleDateFormat;
public class JDBCTest {
/**
* @param args
*/
/**
* @param args
*/
public static void main(String args[]) {
String sql;
Statement stmt_q;
Statement stmt_u;
try {
// Connection connIn = DriverManager.getConnection( "jdbc:sybase:Tds:101.101.101.119:4100/test ", "wonders ", "wonders "); // 内网测试环境 琍 ?charset=eucgb&jconnect_version=6
// Class.forName( "com.sybase.jdbc3.jdbc.SybDriver ");
Connection connIn = DriverManager.getConnection( "jcbc:mysql://localhost:3306/test ", "sichuang ", " "); // 内网测试环境 琍 ?charset=eucgb&jconnect_version=6
Class.forName( "com.mysql.jdbc.Driver ");
stmt_q = connIn.createStatement();
sql = "select * from test ";
stmt_q.executeQuery(sql);
stmt_q.close();
if (connIn!=null){
connIn.close();
connIn = null;
}
/*stmt_u = connIn.createStatement();
sql = "update test2 set col1 = '许佩 ', col2 = 3 where col2 = 4 ";
stmt_u.executeUpdate(sql);
stmt_u.close();
connIn.close();*/
} catch (
ClassNotFoundException e) {
System.out.println( "11111111111 ");
e.printStackTrace();
} catch (
SQLException e) {
System.out.println( "22222222222 ");
e.printStackTrace();
}
System.exit(0);
}
}
但问题是不能运行成功,报错:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JDBCTest.main(JDBCTest.java:22)
22222222222
不管是用mysql还是sybase,烦!
classpath配好了,再jdk\jre\lib\ext\下面也放好了jconn3.jar和mysql-connector-java-5.0.5-bin.jar包。但就是不行。
请各位大侠帮忙看看 谢谢!!!
------解决方案--------------------可以考虑把它们放在同一文件夹下。
------解决方案--------------------将正确的JDBC驱动放在JDK_HOME\jre\lib\ext下