olá pessoas,
fiz um servlet pra fazer uma busca no banco, mas quando o mesmo é executado aparece a mensagem de erro abaixo:
Estou enviando a classe logo abaixo tb…
package clas;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PesquisaBD extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
public PesquisaBD() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/bdestudo","root","sa");
Statement stmt = null;
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from artista");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>");
out.println("TESTE");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<TABLE BORDER="+"0"+"ALIGN="+"CENTER>");
while (rs.next())
{
int valor = rs.getInt("codigio_artista");
String valor_int = ""+valor;
String valor2 = rs.getString("nome_artista");
out.println("<TR>");
out.println("<TD>" + valor_int + "</TD>");
out.println("<TD>" + valor2 + "</TD>");
out.println("</TR>");
}
out.println("</TABLE>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/bdestudo","root","sa");
Statement stmt = null;
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from artista");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>");
out.println("TESTE");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<TABLE BORDER="+"0"+"ALIGN="+"CENTER>");
while (rs.next())
{
int valor = rs.getInt("codigio_artista");
String valor_int = ""+valor;
String valor2 = rs.getString("nome_artista");
out.println("<TR>");
out.println("<TD>" + valor_int + "</TD>");
out.println("<TD>" + valor2 + "</TD>");
out.println("</TR>");
}
out.println("</TABLE>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
valeu!!!