如何修复此程序?
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
class MySqlData {
public static void main(String args[]) throws Exception {
DriverManager.registerDriver(new com.mysql.jdbcDriver());
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test/user=root&password=merimaa");
Statement stmt = con.createStatement();
ResultSet res=stmt.executeQuery("Select * from employee");
while (res.next()) {
System.out.println(res.getString("employee_name"));
}
con.close();
}
}
答案 0 :(得分:2)
正如其他人所说:
答案 1 :(得分:0)
将包含sql驱动程序的相应jar文件添加到类路径
答案 2 :(得分:0)
首先你需要下载一个mysql驱动程序,然后设置一些与mysql连接的异常捕获器,或者抛出一些异常。
答案 3 :(得分:0)
答案 4 :(得分:0)
将Jar文件添加到WEB-INF / lib。
使用以下
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
try {
String connectionURL = "jdbc:mysql://host/db";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "username", "password");
if(!connection.isClosed())
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}catch(Exception ex){
out.println("Unable to connect to database"+ex);
}