ciao a tutti,
dunque, mi sono costruito 1 classe DBconn, che contiene 1 metodo
getResultset() che dovrebbe restituire il risultato di una query:
--------
public ResultSet getResultset(String strSQL) {
Statement stmt = null;
Connection tmpConn = null;
ResultSet rs = null;
errConn = "";
try {
tmpConn = DriverManager.getConnection("jdbc:mysql://localhost/dbbiblio?user=root&password=");
} catch (SQLException ex) {
errConn = ex.getMessage();
}
if ("".equals(errConn)){
try {
stmt = tmpConn.createStatement();
rs = stmt.executeQuery(strSQL);
}
catch (SQLException sqlEx) { errConn = sqlEx.getMessage(); }
finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx) { errConn = sqlEx.getMessage(); }
}
try {
tmpConn.close();
tmpConn = null;
errConn = "";
} catch (SQLException ex) {
errConn = ex.getMessage();
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) { errConn = sqlEx.getMessage(); }
stmt = null;
}
}
}
return rs;
}
--------
poi nella jsp:
-----
DBconn currConn = new DBconn("dbbiblio");
String strUser = request.getParameter("txtUser");
String strPWD = request.getParameter("txtPWD");
currConn.openConn (strUser,strPWD);
ResultSet tblUser = null;
String strSQL;
String strRes;
strSQL = "SELECT * FROM TBuser WHERE CDuser='"+strUser+"'";
strSQL = strSQL+" AND CDpwd='"+strPWD+"'";
tblUser = currConn.getResultset(strSQL);
String strCDuser = "";
if (tblUser==null){
strCDuser = "vuoto";}
else
{ if(tblUser.next()){
strCDuser = tblUser.getString("CDuser");
}
----
mi viene segnalato un errore di operazione non valida dopo la chiusura del recordset.
credo sia un errore logico, ma essendo alle prime armi con java ho qualche difficoltà a trovare gli errori, se poi avete anche 1 classe seria o esempi di codice che utilizza resultset vi ringrazio molto...