Comments
|
Posted By V On 12-Aug-10 11:13:10 PM
is there a way to call a managed bean method onblur, rather than coding the db access in a JSP ?
|
|
Posted By Kurt Pater On 22-Dec-10 10:57:29 PM
Nice article, helps a lot, thanks KP
|
|
Posted By srinivasu On 05-Jan-11 03:49:40 PM
Hi Vikrant for your question, you can move the scriptlet code to a bean class method or else you create a new DAO class where DB connection can be written over here and create an instance of DAO class in bean and perform a method call....
|
|
Posted By Yuri On 21-Feb-11 09:05:07 PM
Let me correct a code with DB connection. During query execution several exceptions may occur. So the code should be put in try/catch block:
<%@ page import="java.sql.*" contentType="text/plain"%>
<%
String username = request.getParameter("username"); // sent from client
// connect to oracle using thin driver
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{ DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","youruser","yourpassword");
ps = con.prepareStatement("select username from users where username = ?");
ps.setString(1,username);
ResultSet rs = ps.executeQuery();
if ( rs.next()) { // found username
out.println("Username is already present!"); // send this to client
}
} catch (Exception e){
if (rs != null){
rs.close();
}
// ... and so on
}
%>
|
|
Posted By himanshu goyal On 07-Dec-12 06:28:42 PM
hiii All
this is good example to understanading of basic jaf
|