Data centric
jsf application
what book i should read for data centric jsf application?
I have some problem with my jsf application using database connection.
I use jsf, managed bean and database bean.I use normal plain
java.
The problem is occured during linking between managed bean and database bean.
Error is variable result might not be initialized.
If any error do not occcur, result is not generated.
The method in managed bean cannot generate result.
why?please give me some example.What book i should read.
I want to use jsf,
jdbc and normal plain java.That is possible?
What effects can cause?
I have no experience in other database component such as entity bean.
My web service directory is apache tomcat.I use odbcjdbc driver and ms access database.
Here is my code.
DatabaseBean.java
package mainclasses;
import java.io.*;
import java.sql.*;
public class DatabaseBean {
private static final
String jdbcDriverClass =
"sun.jdbc.odbc.JdbcOdbcDriver";
private static final String jdbcDatabaseURL =
"jdbc:odbc:Employees";
private Connection conn;
public DatabaseBean() throws Exception {
try {
// Load the JDBC-ODBC driver.
Class.forName(jdbcDriverClass);
// Open a database connection.
connect();
} catch(SQLException ex) {
// Perform any cleanup.
cleanup();
// Rethrow exception.
throw(ex);
}
}
public void connect() throws SQLException {
if(conn != null) {
cleanup();
conn = null;
}
// Open a database connection.
conn = DriverManager.getConnection(jdbcDatabaseURL);
}
public void cleanup() throws SQLException {
// Close the Connection.
if(conn != null) {
conn.close();
}
}
// The onus is on the user to close the Statement that created
// the returned ResultSet.
public ResultSet query(String queryStatement)
throws SQLException {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(queryStatement);
} catch(SQLException ex) {
try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex2) {
}
finally {
throw(ex);
}
}
return(rs);
}
public int insert(String insertStatement) throws SQLException {
return(update(insertStatement));
}
public int delete(String deleteStatement) throws SQLException {
return(update(deleteStatement));
}
public int update(String updateStatement) throws SQLException {
Statement stmt = null;
int numRows = -1;
try {
stmt = conn.createStatement();
numRows = stmt.executeUpdate(updateStatement);
} catch(SQLException ex) {
try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex2) {
} finally {
throw(ex);
}
} finally {
try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex) {
}
}
return(numRows);
}
public Connection getConnection() {
return(conn);
}
}
simplelogin.java
package mainclasses;
import java.sql.*;
import java.io.*;
import mainclasses.*;
public class SimpleLogin{
String loginname;
String password;
String result;
DatabaseBean db;
public SimpleLogin(){}
public String getLoginname(){
return loginname;
}
public void setLoginname(String loginname){
this.loginname = loginname;
}
public String getResult(){
return result;
}
public String getPassword(){
return password;
}
public void setPassword(String password){
this.password = password;
}
public String CheckValidUser(){
String query="SELECT username,password FROM login ";
try{
ResultSet rs=db.query(query);
while(rs.next()){
result=null;
if(loginname.equals(rs.getString("username"))&&password.equals(rs.getString("password")))
{
result="success";
rs.afterLast();
}
else
result="fail";
}
}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return result;
}
}