[英]Getting error while connecting mysql database in java
I have created a program, i need to save the content into mysql database. 我已经创建了一个程序,我需要将内容保存到mysql数据库中。 Could you please help me how to save it through java programming
你能帮我解决一下如何通过java编程保存它
I have set the sqljdbc.jar classpath, but its giving error 我已经设置了sqljdbc.jar类路径,但它给出了错误
I have used the following code 我使用了以下代码
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
java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc:sqlserver://127.0.0.1:8888;" + "databaseName=norton;user=root;password=
doesn't look like a valid connection string for a mysql database. jdbc:sqlserver://127.0.0.1:8888;" + "databaseName=norton;user=root;password=
看起来不像是mysql数据库的有效连接字符串。 Check this. 您是否将Java Build Path设置为包含sql jar?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.