Reputation: 73
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
Upvotes: 0
Views: 490