Hy guys,
i was trying to build an application to communicate with a database.
the connection is not the problem.
the problem is that in the bean i have the method below
public static
String cauta()
{
PreparedStatement pstmt = null;
ResultSet rs=null;
String numm=null;
String prenumm=null;
try{
// Create a statement
//Statement stmt = conn.createStatement();
String sql = "Select * FROM Users WHERE Username=? ";
pstmt = con.prepareStatement(sql);
// Set the value
pstmt.setString(1, username);
rs= pstmt.executeQuery();
if (rs.next()) {
numm=rs.getString("Name");
prenumm=rs.getString(3);
System.out.println(numm+" "+prenumm);
System.out.println("SQL statement is executed!");
rez= "S-a gasit userul cautat. Se numeste: "+numm+" "+prenumm;
return rez;
}
else {
rez= "User-ul cautat nu a fost gasit";
return rez;
}
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
s.printStackTrace();
}
catch (Exception e){
e.printStackTrace();
}
return null;
}
the method works just fine and return the appropriate string
but in the
jsp file i can't manage to acces this method in order to display that string in my page.
i've tried even javascript but it won't work
<h:outputText value="Username"/>
<h:inputText id="user" value="#{Bean.username}" autocomplete="on"/>
<h:commandButton onclick="alert(Core.JSPBean.getRez().toString())" action="#{Bean.cauta}" id="submit" value="Cauta" />
are there any other ways in which i can display this damn message on my page?
Thanks for your help!