import java.io.*;
import java.sql.*;
import java.util.*;
import javax.naming.*;
public class Controller {
public static String processUser(String sqlStmt, String whichSvlt){
String st ="";
String first_name = null;
String last_name;
String ssn;
String email;
String address;
String userid;
String password;
List<StudentInfo> result = new ArrayList<StudentInfo>();
// later I will use whichSvlt to guide the result to desired output point
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("DataBase");
conn = ds.getConnection();
stmt = conn.createStatement();
// takes SQL statements from Login and Register servlets:
rs =stmt.executeQuery(sqlStmt);
System.out.println();
// Reads data objects in database Going Forward
while (rs.next()) {
//for (int i = 1; i <= meta.getColumnCount(); i++) {
st = rs.getObject(1) + " " +rs.getObject(2);
//String name = rs.getString("fname");
first_name = rs.getObject(1).toString();
last_name = rs.getObject(2).toString();
ssn = rs.getObject(3).toString();
email = rs.getObject(4).toString();
address = rs.getObject(5).toString();
userid = rs.getObject(6).toString();
password = rs.getObject(7).toString();
// tried below but didn't work so commented out
// StudentInfo student = new StudentInfo(); // Creating a Student object to fill with Student data
// student.setstdFn(first_name);
// student.setstdLn(last_name);
// student.setstdSsn(ssn);
// student.setstdEml(email);
// student.setstdAdd(address);
// student.setstdUId(userid);
// student.setstdpwd(password);
//Add the retrived Student to the list
//result.add(student);
System.out.println(st); // this works without the object and I can see the result in sys_out
//System.out.println(first_name);
}
//Close JDBC objects as soon as possible
//default title and icon
stmt.close();
conn.close();
}catch(Exception e) {e.printStackTrace();}
finally {
try {
ctx.close();
} catch (Exception e) {System.out.println(e);}
try {
if (rs != null) rs.close();
} catch (Exception e) {System.out.println(e);}
try {
if (stmt != null) stmt.close();
} catch (Exception e) {System.out.println(e);}
try {
if (conn != null) conn.close();
} catch (Exception e) {System.out.println(e);}
}
return st; // this is the value I want to retrieve with another servlet
// I can print it in my terminal window but always show up as null in the other servlet
}
}
Rodney_2 0 \_O_/
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.