I have created a program, i need to save the content into mysql database. Could you please help me how to save it through java programming
I have set the sqljdbc.jar classpath, but its giving error
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
com.mysql.jdbc.Driver) you're using is for MySQL, but sqljdbc.jar is the JAR you use to connect to SQL Server, the connection string also suggests SQL Server, and your ClassNotFoundException (which appears not to match your code) mentions the SQL Server driver. Furthermore, the SQL (SELECT TOP n ...) is valid in SQL Server but not in MySQL.