Olá pessoal, alguem pode me dar uma ajuda sobre o código abaixo, estou com as mensagens de erro que apontei. Este código esta dentro de um jButton1 e foi feito no NetBeans.
Fiz os seguintes imports
import com.itextpdf.text.;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.sql.ResultSet;
import java.sql.SQLException;
[color=red] public class bdados() { //ERRO: ILLEGAL START OF EXPRESSION[/color]
private Statement stmt = null;
private Connection conn = null;
public ResultSet consulta() throws SQLException, ClassNotFoundException{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://Localhost:3306/dbjava","root","");
stmt = conn.createStatement();
String sql = "SELECT * FRON tbagenda";
ResultSet res = stmt.executeQuery(sql);
return (res);
}
public bdados(){
Document doc = new Document();
try{
ResultSet contatos = consulta(); //UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN
PdfWriter.getInstance(doc, new FileOutputStream ("Relatorio.pdf"));
doc.open();
Font f = new Font(FontFamily.HELVETICA, 30, Font.BOLDITALIC|Font.BOLD);
PdfPTable t = new PdfPTable(3);
Image jpg = Image.getInstance("itext.jpg");
jpg.scalePercent(30);
PdfPCell cell = new PdfPCell();
cell.setBorder(PdfPCell.NO_BORDER);
cell.addElement(jpg);
t.addCell(cell);
PdfPCell cell1 = new PdfPCell();
cell1.setBorder(PdfPCell.NO_BORDER);
cell1.setColspan(2);
f.setColor(0, 255, 0);
f.setSize(20);
cell1.addElement(new Paragraph("Programação Java\n",f));
cell1.addElement(new Paragraph("Relatório PDF\n",f));
f.setSize(16);
cell1.addElement(new Paragraph("Prof. Marcos Tadeu Mourão\n",f));
t.addCell(cell1);
doc.add(t);
PdfPTable table = new PdfPTable(5);
PdfPCell coluna1 = new PdfPCell(new Paragraph ("Código"));
coluna1.setBackgroundColor(new BaseColor (0xc0, 0xc0, 0xc0));
coluna1.setMinimumHeight(30);
PdfPCell coluna2 = new PdfPCell(new Paragraph ("Nome"));
coluna2.setBackgroundColor(new BaseColor (0xc0, 0xc0, 0xc0));
PdfPCell coluna3 = new PdfPCell(new Paragraph ("Cidade"));
coluna3.setBackgroundColor(new BaseColor (0xc0, 0xc0, 0xc0));
PdfPCell coluna4 = new PdfPCell(new Paragraph ("Telefone"));
coluna4.setBackgroundColor(new BaseColor (0xc0, 0xc0, 0xc0));
PdfPCell coluna5 = new PdfPCell(new Paragraph ("Email"));
coluna5.setBackgroundColor(new BaseColor (0xc0, 0xc0, 0xc0));
table.setWidths(new int[]{25,40,40,40,70});
table.addCell(coluna1);
table.addCell(coluna2);
table.addCell(coluna3);
table.addCell(coluna4);
table.addCell(coluna5);
while(contatos.next()){
[color=red] String codigo = contatos.getString("codigo");//UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN
String nome = contatos.getString("nome");//UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN
String telefone = contatos.getString("telefone");//UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN
String email = contatos.getString("email");//UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN
String cidade = contatos.getString("cidade");//UNREPORTED EXCEPTION JAVA SQL.SQLEXCEPTION; MUST BE CAUGHT OR DECLARED TO BE THROWN[/color] table.addCell(codigo);
table.addCell(nome);
table.addCell(telefone);
table.addCell(email);
table.addCell(cidade);
}
doc.add(table);
}catch (DocumentException de){
System.err.println(de.getMessage());
}catch(IOException ioe){
System.err.println(ioe.getMessage());
}
doc.close();
}