我已经创建了一个程序,我需要将内容保存到mysql数据库中。你能帮我解决一下如何通过java编程来保存它 我已经设置了sqljdbc.jar类路径,但它给出了错误
我使用了以下代码
import java.sql.*;
public class connectURL {
public static void main(String[] args) {
String connectionUrl = "jdbc:sqlserver://127.0.0.1:8888;" +
"databaseName=norton;user=root;password=";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionUrl);
String SQL = "SELECT TOP 10 * FROM demopoll";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString(4) + " " + rs.getString(6));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}
ERROR:
java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver
答案 0 :(得分:2)
jdbc:sqlserver://127.0.0.1:8888;" +
"databaseName=norton;user=root;password=
看起来不像是mysql数据库的有效连接字符串。检查一下。答案 1 :(得分:0)
您是否将Java Build Path设置为包含sql jar?