• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connecting to a SQL database or ODBC DSN

 
r merritt
Greenhorn
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;
Class.forName(driver).newInstance();
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.setContentType("text/csv");
   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"));
   }
  }
  else
  {
  out.println("Hello <b>"+request.getParameter("name")+"</b>!");
  }
}
else
{
  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());
}
%>
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • 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