• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

connecting to a SQL database or ODBC DSN  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error when trying to connect to a particular :
SQLException: No suitable driver found for jdbc:sqlserver://udwsqltest.usask.ca:1433/UDWSQLState: 08001VendorError: 0

here is the code how do I make this work am I missing the driver?

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* " %>
<%@ page import="java.io.*" %>
try {
String driver = "org.sqlserver.Driver";
String url = "jdbc:sqlserver://udwsqltest.usask.ca:1433/UDW";
String username = "user";
String password = "<fakepassword>";
String myDataField = null;
String myQuery1 = "SELECT  uid,student_sid from d_student;";
String myQuery = "SELECT  uid,student_sid from d_student;";
Connection myConnection = null;
PreparedStatement myPreparedStatement = null;
ResultSet myResultSet = null;
myConnection = DriverManager.getConnection(url,username,password);
myPreparedStatement = myConnection.prepareStatement(myQuery);
myResultSet = myPreparedStatement.executeQuery();

if ((request.getParameter("sd") != null) || (request.getParameter("ed") != null))
 if (request.getParameter("excel") != null)
  response.setHeader("Content-Disposition", "attachment; filename=MSmult_table.csv");
  out.println("AuditID,object Type Id,Object Id,User Name,Action Type ID,Action Success ID,Time Stamp") ;
  while (myResultSet.next())
    out.println(myResultSet.getString("uid") + "," + myResultSet.getString("stuednt_sid"));
 out.println("Hello <b>"+request.getParameter("name")+"</b>!");
 out.println("Hello <b>Select a date range and click submit to generate list of logins for the time span</b>!");

catch(ClassNotFoundException e){e.printStackTrace();}
catch (SQLException ex)
out.print("SQLException: "+ex.getMessage());
out.print("SQLState: " + ex.getSQLState());
out.print("VendorError: " + ex.getErrorCode());
Posts: 3743
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the driver deployed with your webapp?

That aside (and I expect you'll say you've been told to do it like this) but you shouldn't have Java code in a JSP page like that.
That should be handled via a servlet, probably calling a service, which then gathers the data you need.  That is then passed onto the JSP page which simply has to handle displaying the result.

Also, you might want to look into connection pools for whatever server you are using, later on.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!