Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Conecta(){
- // try{
- // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- // }
- // catch (Exception excessao){
- // JOptionPane.showMessageDialog(null," SQL Exception "+ excessao.getMessage()+
- // " Erro de Carga de Banco de Dados ");
- // }
- try {
- conexao = DriverManager.getConnection("jdbc:mysql://localhost:8080/cursos", "root", "");
- System.out.println("Conectado!");
- comando = conexao.createStatement();
- }
- catch (Exception excessao){
- JOptionPane.showMessageDialog(null," SQL Exception "+ excessao.getMessage()+
- " Erro ao conectar ao Carga de Banco de Dados ");
- }
- }
- private void InsereDados() {
- do{
- strCurso = (String)JOptionPane. showInputDialog("Digite o numero do Curso:");
- }while(strCurso == null);
- do{
- strNome = (String)JOptionPane. showInputDialog("Digite o nome do Curso:");
- }while(strNome == null);
- do{
- strDuracao = (String)JOptionPane. showInputDialog("Digite A Carga Horaria do Curso:");
- }while(strDuracao == null);
- private void Insert(){
- if ((strCurso != null)&&(strNome != null)&&(strDuracao != null)) {
- try {
- PreparedStatement strComandoSQL ;
- strComandoSQL = conexao.prepareStatement( "INSERT INTO curso(CDCurso,NMCurso,NRDuracao)" + " VALUES(?,?,?)");
- strComandoSQL.setInt(1,Integer.parseInt(strCurso));
- strComandoSQL.setString(2,strNome);
- strComandoSQL.setInt(3,Integer.parseInt(strDuracao));
- int intRegistro = strComandoSQL.executeUpdate();
- if (intRegistro != 0){
- JOptionPane.showMessageDialog(null,"Registro adicionado !", "Mensagem",JOptionPane.INFORMATION_MESSAGE);
- comando.close();
- conexao.close();
- }
- else{
- JOptionPane.showMessageDialog(null,"Registro nao adicionado !", "Mensagem",JOptionPane.INFORMATION_MESSAGE);
- comando.close();
- conexao.close();
- }
- }
- catch (Exception Excecao) {
- JOptionPane.showMessageDialog(null,"SQLException: " + Excecao.getMessage(),"Erro: Selecaoo de registro", JOptionPane.INFORMATION_MESSAGE);
- }
- } else {
- JOptionPane.showMessageDialog(null,"Falta Preencher Campo!", "Mensagem",JOptionPane.INFORMATION_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement