este es el código q uso
public void example_query (Connection conn, javax.servlet.jsp.JspWriter out) throws Exception {
out.println("Mostrar los USUARIO en la BD.<br />\n");
// Prepare a query containing a bind variable.
String sql = "select ID, NOMBRE, APELLIDO from BIBLIOTECA.PRUEBA ORDER BY ID ASC";
PreparedStatement stmt = conn.prepareStatement(sql);
// Execute the completed statement.
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
// Do something with the data
out.println("ID=" + rs.getString("ID"));
out.println(" NOMBRE=" + rs.getString("NOMBRE"));
out.println(" APELLIDO=" + rs.getString("APELLIDO") + "<br />\n");
}
stmt.close();
stmt = null;
}
public void example_insert (Connection conn, javax.servlet.jsp.JspWriter out, HttpServletRequest request) throws Exception {
// Prepare an insert statement containing bind variables.
String sql = "INSERT INTO BIBLIOTECA.PRUEBA(ID, NOMBRE, APELLIDO) VALUES(?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(sql);
// Bind the value into the prepared statement.
String id= "null";
// String nombre= "nombre";
String apellido= request.getParameter("apellido");
String nombre= request.getParameter("nombre");
stmt.setString(1, id);
stmt.setString(2, nombre);
stmt.setString(3, apellido);
// Execute the completed statement.
if (request.getParameter("action").equals("Guardar")){
int res = stmt.executeUpdate();
out.println("<br />Insert a new employee.<br />\n");
}
stmt.close();
stmt = null;
out.println("Usuario Insertado Satisfactoriamente.<br />\n");
}
}
// Start the main body of the code.
try {
// Instantiate the functions class.
PageFunctions funcs = new PageFunctions();
// Connect to the SCOTT schema of the DB10G database.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "biblioteca", "Pa55w0rd");
out.println("Connected sucessfully.<br /><br />\n");
//funcs.example_query(conn, out);
funcs.example_insert(conn, out, request);
//funcs.example_query(conn, out);
conn.close();
conn = null;
out.println("<br />Disconnected sucessfully.<br /><br />\n");
} catch (Exception ex) {
//out.println(" Error: " + ex.getLocalizedMessage() + "<br><br>\n");
}