Hello,
I am creating a DBConnection Class that I am creating an instance of in a login class.
In this login class I pass a dynamic query string to DBConnection. I have this
deployed on a Weblogic server. (yes I registered the servlet :) )I have an index page
that calls a Login servlet where the DbConnection instance is. I have registered the
Data source name for my access 2000 database and still I get a server 500 error. I
don't have a URL to show but all my code for the two classes is as follows:
package com.thehartford.MusicStore;
/**
* This class will define a connection to the MusicStore Database written in Microsoft
Access 2000
* Creation date: (11/24/00 3:03:11 PM)
* @author: Travis D. Falls
*/
import java.sql.*;
import java.util.*;
public class DBConnection {
private Connection connection;
public String query1;
Statement stmt;
ResultSet rs;
public DBConnection(){
String pass;
String userId;
String url = "jdbc:odbc:MusicStore";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(
url);
}
catch(ClassNotFoundException cnfex){
System.err.println("Failed to load JDBC/ODBC Bridge Driver.");
cnfex.printStackTrace();
//System.exit(1);//Terminates attempted Connection
}
catch(SQLException sqlex){
System.err.println("Unable to Connect");
sqlex.printStackTrace();
}
try{
stmt = connection.createStatement();
rs = stmt.executeQuery(query1);
stmt.close();
}
catch( SQLException sqlex){
sqlex.printStackTrace();
}
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
package com.thehartford.MusicStore;
/**
* Login Class accesses MusicStore Database and validates the user as being registered.
* Creation date: (11/24/00 3:00:29 PM)
* @author: Travis D. Falls
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class Login extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws
ServletException, IOException{
PrintWriter out;
res.setContentType("text/html");
out = res.getWriter();
StringBuffer buf = new StringBuffer();
String Un, Pw, Bn;
Un= req.getParameter("UserId");
Pw= req.getParameter("Password");
Bn= req.getParameter("BusinessName");
String pass = Pw;
String userId = Un;
String query= ("Select * from Customer where CustomerId = " +"'" + userId +
"'" + " and Password = " + "'" + pass + "'");
DBConnection c = new DBConnection();
c.query1=query;
try{
if (c.rs.next()){
out.println ("you are in");
}
else{
out.println ("error on page");
}
}
catch(SQLException e){
out.println("SQL exception catught in the lgoin class " +
e.getMessage());
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws
ServletException, IOException{
PrintWriter out;
res.setContentType("text/html");
out = res.getWriter();
StringBuffer buf = new StringBuffer();
String Un, Pw, Bn;
Un= req.getParameter("UserId");
Pw= req.getParameter("Password");
Bn= req.getParameter("BusinessName");
String pass = Pw;
String userId = Un;
String query= ("Select * from Customer where CustomerId = " +"'" + userId +
"'" + " and Password = " + "'" + pass + "'");
DBConnection c = new DBConnection();
c.query1=query;
try{
if (c.rs.next()){
out.println ("you are in");
}
else{
out.println ("error on page");
}
}
catch(SQLException e){
out.println("SQL exception catught in the lgoin class " +
e.getMessage());
}
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets