This is the code:
package com.coupon;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLDataException;
import java.sql.SQLException;
public class MainSqlConnection {
public static class JdbcUtils {
public static void main(String[] args) throws SQLException {
String server = "DESKTOP-C7IQ9EE";
String port = "3306";
String user = "CouponProject";
String password = "1234";
String database = "new";
String jdbcurl="jdbc:sqlserver://server:port;DatabaseName=new";
Connection con = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
jdbcurl = "jdbc;sqlserver://' "+ server + ":" +port + ";user=" + user +
";password=" +password + ";databasename=" + database + "";
try{
con = DriverManager.getConnection(jdbcurl,"CouponProject","1234");
}catch(SQLException e){
e.printStackTrace();
}
try{
PreparedStatement pst = con.prepareStatement("select * from ID");
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println("ID="+rs.getInt("ID")+"user="+rs.getString("Name"));
}
}catch(SQLDataException e){
e.printStackTrace();
}
}
}
}
and the exception is this:
java.sql.SQLException: No suitable driver found for jdbc;sqlserver://'
DESKTOP-C7IQ9EE:3306;user=CouponProject;password=1234;databasename=new
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.coupon.MainSqlConnection$JdbcUtils.main(MainSqlConnection.java:34)
Exception in thread "main" java.lang.NullPointerException
at com.coupon.MainSqlConnection$JdbcUtils.main(MainSqlConnection.java:39)
we tried to do Window>>Perspective>>open perspective>>other>>Database development>>right click on Database connection>>the we chose SQL server and next>> and we didn't have the find driver button that suppose to appear near the driver section on the top right of the window we did implement the jar through build path and we also imported the java into the lib folder we don't know what wrong please help us thank u very much.
The option that you describe is for eclipse (internal) database explorer.
So, for your project:
Now, the program can load SQLDriver from jar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With