Does this servlet look correct? It compiles ok but my dot.jsp file returns error like "can't find connStatement()". I'm learning while I do this so I can't tell if everything here is good. Also my // comments. - [EMAIL PROTECTED]
package dbdemo; // identifies package
import java.sql.*; // gets class libraries
public class d_sx_123 { // define new class
public static Connection getConnection() { // define first method
Connection conn = null;
// declare reference 'conn' to object of type 'Connection'
try { // monitors block, throws exception to catch{ }
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver()); // thin jbdc driver
conn = DriverManager.getConnection("site:port:db", "id", "pw"); // port is 1521
// now 'conn' is linked with an object
}
catch (Exception e) { // only if exception occured
conn = null;
}
return conn; // now method returns 'conn' to calling routine
}
public static String connStatement() { // define second method
Connection conn = getConnection(); // declares 'conn'
String value = ""; // declare String
try { // monitors block; throws exception to catch(){...}
Statement stmnt = conn.createStatement(); // sql statement object
ResultSet rs = stmnt.executeQuery("select id from emp"); // sql
while (rs.next()) { // loop collects rows
value = value + (rs.getInt("id"); // catenates results
}
rs.close();
stmnt.close();
conn.close();
}
catch(SQLException sqle) { // because try failed
System.out.println(sqle);
}
return value; // purpose of second method
}
}
