Olá pessoal,
estou tentando realizar um select com um scriplet porem nao estou conseguindo, da uma olhada nos arquivos:
Tenho minha classe de conexao e consulta
Conexao.java
... //conexao com o mysqlpublic Conexao() {
try {
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/projeto/","root","senha");
stm = con.createStatement();
} catch (Exception e) {
System.out.println("não foi possível conectar ao banco" + e.getMessage());
}
}
public void setConsulta() {
try {
res = stm.executeQuery("select * from usuarios");
}
catch (SQLException e){
e.printStackTrace();
}
}
public ResultSet getResultado() {
return res;
}
}
...
//conexao com o mysql
public Conexao() {
try {
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/projeto/","root","senha");
stm = con.createStatement();
} catch (Exception e) {
System.out.println("não foi possível conectar ao banco" + e.getMessage());
}
}
.. //meu metodo de consulta
public void setConsulta() {
try {
res = stm.executeQuery("select * from usuarios");
}
catch (SQLException e){
e.printStackTrace();
}
}
public ResultSet getResultado() {
return res;
}
}
agora o jsp que esta fazendo a chamada desse metodo:
listar.jsp
try {
con.setConsulta();
ResultSet temp = con.getResultado();
while (temp.next()){
%>
<tr>
<td width=200>
<%out.println(temp.getString("nome"));%>
</td>
<td width=50>
<%out.print(temp.getString("usuario"));%>
</td>
<td width=30>
<%out.print(temp.getString("senha"));%>
</td>
</tr>
<%}
}catch (Exception e) {
out.println("Não foi possivel realizar a listagem: "+ e.getMessage());
}
%>
try {
con.setConsulta();
ResultSet temp = con.getResultado();
while (temp.next()){
%>
<tr>
<td width=200>
<%out.println(temp.getString("nome"));%>
</td>
<td width=50>
<%out.print(temp.getString("usuario"));%>
</td>
<td width=30>
<%out.print(temp.getString("senha"));%>
</td>
</tr>
<%}
}catch (Exception e) {
out.println("Não foi possivel realizar a listagem: "+ e.getMessage());
}
%>
vlw...