Salve… eu novamente… seguinte eu estou criando uma pequena aplicaçao para pegar valores no banco e colocar dentro de um textArea…mais ou menos assim:[code]
import java.awt.event.;
import javax.swing.;
import java.awt.;
import java.sql.;
import java.io.*;
public class RelatorioTela extends javax.swing.JFrame {
public Connection con = null;
public Statement stm = null;
public ResultSet rs;
public RelatorioTela() {
initComponents();
setLocationRelativeTo(null);
setIconImage(Toolkit.getDefaultToolkit().getImage("c:\\ricardo\\telas\\sgod.jpg"));
criaRelat();
}
// <editor-fold defaultstate="collapsed" desc=" Código Gerado ">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
areaDeTexto = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
btnSair = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Relat\u00f3rio Tela");
setResizable(false);
areaDeTexto.setColumns(20);
areaDeTexto.setRows(5);
jScrollPane1.setViewportView(areaDeTexto);
jLabel1.setText("Este \u00e9 apenas um exemplo de como suas contas foram cadastradas no sistema e seus valores.");
btnSair.setIcon(new javax.swing.ImageIcon("C:\\ricardo\\telas\\sgod.JPG"));
btnSair.setText("SAIR");
btnSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSairActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 763, Short.MAX_VALUE)
.addComponent(jLabel1)
.addComponent(btnSair, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSair)
.addGap(15, 15, 15)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void criaRelat(){
areaDeTexto.setText(“Nome fixa\tValor\tVencimento\tNome Extra\tValor\tVencimento\n”);
System.out.println(“Nome fixa\tValor\tVencimento\tNome Extra\tValor\tVencimento\n”);
try{
Class.forName(“com.mysql.jdbc.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost/dbsgod”, “root”, “”);
stm = con.createStatement();
rs = stm.executeQuery(“select * from contafixa,contaextra”);
while(rs.next()){
String nmfix = rs.getString(2);
float vlrfix = rs.getFloat(3);
String vencfix = rs.getString(4);
String nmext = rs.getString(6);
float vlrext = rs.getFloat(7);
String vencext = rs.getString(8);
//areaDeTexto.setText("%s",nmfix);//esse sobrescreve o de cima
//e a qui diz que o se usar %s por exemplo, não pode porque
//é da classe javalang.String e o textArea e do swing.text.JTextComponet e
//não deixa
System.out.printf("%s\t %8.2f\t %s\t %s\t %8.2f\t %s\n",nmfix,vlrfix,vencfix,nmext,vlrext,vencext);
}
}
catch(Exception e){
JOptionPane.showMessageDialog(this,“Apresente este erro\nao desenvolvedor do sistema.”,“E R R O”,JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
}
}
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
dispose();
}//GEN-LAST:event_btnSairActionPerformed
public static void main(String args[]) {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (UnsupportedLookAndFeelException e){
// handle exception
}
catch (ClassNotFoundException e) {
// handle exception
}
catch (InstantiationException e) {
// handle exception
}
catch (IllegalAccessException e) {
// handle exception
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RelatorioTela().setVisible(true);
}
});
}
// Declaração de variáveis - não modifique//GEN-BEGIN:variables
private javax.swing.JTextArea areaDeTexto;
private javax.swing.JButton btnSair;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
// Fim da declaração de variáveis//GEN-END:variables
}[/code]
só que ele esta colocando apenas o ultimo registro acessado dentro do banco. Como faria para concatenar corretamente e salvar tudo no JTextArea certinho? Na saida formatada vai legal… onde está meu erro?
Obrigado por enquanto…
Ricardo