ok midianet use netbeans,
fiz tudo isso,
em adicionar biblioteca, escolhi a opção: Extensões de Layout do Swing, coloquei o jar lá da past lib que
havia criado no projeto, limpei e construi e agora tá dando o erro:
SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
The Connection descriptor used by the client was:
127.0.0.1:1521
estou quase desistindo disso, não sei se o erro está na classpath da minha maquina. sei lá
mas de qq forma vou postar todo o código:
package cadastrafuncionario;
import java.awt.;
import java.awt.event.;
import java.sql.;
import javax.swing.;
public class CadastraFuncionario extends JFrame {
private JLabel l1, l2, l3, l4, l5;
private JTextField t1, t2, t3, t4, t5;
private JButton b1, b2;
public CadastraFuncionario() {
l1 = new JLabel("Código: ");
l2 = new JLabel("CPF: ");
l3 = new JLabel("Nome: ");
l4 = new JLabel("Sálario: ");
l5 = new JLabel("Departamento: ");
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
t4 = new JTextField(10);
t5 = new JTextField(10);
b1 = new JButton("Gravar no Oracle");
b2 = new JButton("Fechar");
b1.addActionListener(new Ouvinte());
b2.addActionListener(new Ouvinte());
t4.addActionListener(new Ouvinte());
Container c = getContentPane();
c.setLayout(new GridLayout(6,2));
c.add(l1); c.add(t1);
c.add(l2); c.add(t2);
c.add(l3); c.add(t3);
c.add(l4); c.add(t4);
c.add(l5); c.add(t5);
c.add(b1); c.add(b2);
setSize(500,300);
setTitle("Cadastro de Funcionário");
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
CadastraFuncionario janela = new CadastraFuncionario();
janela.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private class Ouvinte implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource()==b1) {
String url = "jdbc:oracle:thin:@127.0.0.1:1521";
Connection con;
String query = "INSERT INTO FUNCIONARIO (" +
" CODIGO_FUNCIONARIO, CPF," +
" NOME_FUNCIONARIO, SALARIO, DEPARTAMENTO" +
") VALUES ('" +
t1.getText().trim() + " ', '" +
t2.getText().trim() + " ', '" + t3.getText().trim() + " ', '" +
t4.getText().trim() + " ', '" + t2.getText().trim() + " ', ')";
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(java.lang.ClassNotFoundException e1) {
System.err.print("ClassNotFoundException:");
System.err.println(e1.getMessage());
}
try {
con = DriverManager.getConnection(url, "VALDECYR", "5525or");
stmt = con.createStatement();
int rs = stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null, "inserção de Funcionário efetuada com sucesso!");
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}// fim do botão 1
else
if (e.getSource()==b2) {
/* 0 = YES_OPTION
* 1 = NO_OPTION
* 2 = CANCEL_OPTION
*/
int x = JOptionPane.showConfirmDialog(null, "Deseja Fechar a Janela?");
if (x == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Fechando a janela de Cadastro de Funcionário");
dispose();
}
}
}
}
}
Abraço a todos,
Valdecyr