java从Tomcat servlet使用MySQL JDBC的样板是什么?
我想从Tomcatservlet使用JDBC连接到MySQL数据库
这就是我所尝试的:
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://DatabaseURL",
"username", "password");
Statement statement = connection.createStatement();
String sqlQuery = "use db name;";
statement.executeUpdate(sqlQuery);
我在eclipse中导入了JDBC并将其放在src文件夹中
我做错了什么
# 1 楼答案
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "");
Statement statement = connection.createStatement();
刚刚编译了这段代码,它工作得很好