Issue
I have to connect my database with java. The program work fine in my Eclipse IDE but when i export in jar file . I get this error: connection failure: No suitable driver found for jdbc:sqlserver://myServer:1433;databaseName=mydb
This is my code
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class DriverManagerSql {
public static void main(String[] args) {
Connection connection = null;
String dbUrl = "jdbc:sqlserver://myServer:1433;databaseName=mydb";
String username = "sa";
String password = "12345";
try {
connection = DriverManager.getConnection(dbUrl, username, password);
if (connection != null) {
JOptionPane.showMessageDialog(null, "good connection");
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "connection failure:" + e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
System.err.println("Error while closing the connection: " + e.getMessage());
}
}
}
}
I want the same result as the ide
Solution
I resolved the problem by reinstalling JDK on my PC.
Answered By - met8657
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.