简体   繁体   中英

No suitable driver found for JDBC SQL server

I am building a GWT program that on the server side connects to a database named TheDatabase. I tested my code by running it in a Java project, and it worked beautifully. However, when I try running it as part of the GWT project, I get this error:

java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName=TheDatabase;integratedSecurity=true;

This is my function to connect to a database:

public void getConnection(String server, String database) throws SQLException{
    this.connection = DriverManager.getConnection("jdbc:sqlserver://" + server + ";" + 
            "databaseName=" + database + 
            ";integratedSecurity=true;");
}

And this is the code I call where the error happens:

private ResultSet executeQuery(String sqlCommand) throws SQLException{
    Statement stat = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    return stat.executeQuery(sqlCommand);
}

Server-side dependencies should be in the WEB-INF/lib folder of your war folder. It's not enough to put them in the DevMode classpath.

You have to download the driver's .jar file and make it available in you claspath, so the DriverManager can instantiate it by reflection, based on your connection string.

However, in GWT while you program all in Java, there is a server-side code and a client-side code, that ends up compiled as Javascript. Are you sure you are not trying to connect to the DB from the client part of your code? (Based on your comment that it worked before you turned it into a GWT project).

Also, make sure you haven't checked the "Google App Engine" setting of you project, because GAE does not work with JDBC (check this just in case: JDBC Driver does not work with GWT? )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM