求助关于Java连接mysql数据库的问题,能编译但是运行异常
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//class mytest2
public class test2 {
public static void main (String args[])throws ClassNotFoundException,SQLException {
Connection con = JDBCTool.getConnection("jdbc:mysql://localhost:3306/test","root","159753");
Statement st = con.createStatement();
ResultSet re = st.executeQuery("select * from stu");
while(re.next()){
String title=re.getString("name");
re.getInt("id");
System.out.println(title);
}
re.close();
st.close();
con.close();
}
}
//class JDBCTool
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCTool {
public static Connection getConnection(String url,String user,String password)throws ClassNotFoundException,SQLException{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection(url,user,password);
}
}
不知道是怎么回事了,求解!!
Java mysql 数据库连接
[解决办法]
mysql连接jar包没有啊