对不起我的英语不好,我想用java连接mysql连接,我添加了mysql-connector.jar但找不到类错误仍然继续。这是构建路径的屏幕截图。
连接mysql应该怎么做
这是代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
String sql1 = "INSERT INTO test (name) VALUES(?)";
stmt = conn.prepareStatement(sql1);
stmt.setString(1, okey);
}
// execute insert SQL stetement
stmt .executeUpdate();
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
}//end finally try
}//end try