Help Me to Understand Class Instances
I need to know why the following will not work and how to fix it.
My connection class:
package com.ibm.drawinginquiry.rational;
import java.sql.*;
import com.ibm.as400.access.*;
publicclass LogOnConnection{
public LogOnConnection(){
AS400JDBCDataSource datasource =new AS400JDBCDataSource("gvas400");
datasource.setUser("userid");
datasource.setPassword("password");
try
{
Connection connection = datasource.getConnection();
}
catch (SQLException se)
{
System.err.println("Exception creating the database connection: "+se);
}
}
}
My Servlet:
[CODE]
public static String conn;
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1)
*/
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
this.doPost(arg0, arg1);
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest arg0, HttpServletResponse arg1)
*/
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
String useridp = arg0.getParameter("louserid");
String passwordp = arg0.getParameter("lopassword");
LogOnConnection conn = new LogOnConnection();
RequestDispatcher disp = getServletContext().getRequestDispatcher("/MainMenu.jsp");
disp.forward(arg0, arg1);
}
}
[/CODE]
My SQL Class:(My trouble is conn cannot be resolved)
[CODE]
package com.ibm.drawinginquiry.rational;
import java.sql.*;
import com.ibm.as400.access.*;
public class LogOnDataClass {
LogOnDataClass(){
try{
String userfname = null;
String userlname = null;
String sql = "SELECT fname, lname FROM webprddt6.appusrprf1 WHERE usrid = 'SDE'";
Statement sment = conn.createStatement();
ResultSet rs = sment.executeQuery(sql);
if ( rs.next() ) {
userfname = rs.getString("fname");
userlname = rs.getString("lname");
} else {
}
rs.close();
sment.close();
} catch ( SQLException se ) {
System.err.println("Exception performing query: "+se);
}
}
}
[/CODE]

