visto che ho un pò di tempo torno sull'argomento.
ho questa classe:
codice:
public class Leggi {
private String i = null;
private String e = null;
private String u = null;
private String c = null;
private String d = null;
private String line = null;
public String getLine() {
return line;
}
public String leggi() {
int numcolonne = 0;
String nomecolonne = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
try {
conn = Connessione.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from movimenti");
rsmd = rs.getMetaData();
numcolonne = rsmd.getColumnCount();
for (int i = 1; i <= numcolonne; i++) {
nomecolonne += rsmd.getColumnLabel(i) + ": ";
}
while (rs.next()) {
i = rs.getString(1);
e = rs.getString(2);
u = rs.getString(3);
c = rs.getString(4);
d = rs.getString(5);
line += i + ": " + e + ", " + u + ", " + c + ", " + d + "\n";
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
return nomecolonne + "\n" + line;
}
}
}
i parametri di connessione sono in Connessione.getConnection e sono giusti.
nella jsp ho fatto così:
codice:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="connection" scope="page" class="operazioni_database.Leggi" />
<jsp:getProperty name="connection" property="line" />
<% out.println(connection.getLine()); %>
</body>
</html>
ottengo solo null null.
dove intoppo??