public void conectarBaseDeDatos() {
    try {
      final String CONTROLADOR = "org.postgresql.Driver";
      Class.forName(CONTROLADOR);
      // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb";
      conexion =
          DriverManager.getConnection(
              "jdbc:postgresql://" + main.ipSeleccionada + "/" + objUtils.nameBD, user, pass);
      // conexion = DriverManager.getConnection("jdbc:postgresql://127.0.0.1/goliak_jg", "postgres",
      // "majcp071102kaiser");

      sentencia = conexion.createStatement();
      /*JOptionPane.showMessageDialog(null, "si conecta");*/
    } catch (ClassNotFoundException ex1) {
      // ex1.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver." + ex1.getMessage());
      System.exit(1);
    } catch (SQLException ex) {
      // ex.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(
          null,
          "Error Creacion Statement."
              + ex.getMessage()
              + " / "
              + url
              + " / "
              + user
              + " / "
              + pass);
      System.exit(1);
    }
  }
  public void conectarBDdinamic(String ip) {

    if (ip == null) {
      ip = "192.168.8.231";
    }
    url = "jdbc:postgresql://" + ip + "/ventasalm";
    // javax.swing.JOptionPane.showMessageDialog(null, url);
    String estado;
    try {

      final String CONTROLADOR = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
      Class.forName(CONTROLADOR);
      // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb";
      conexion = DriverManager.getConnection(url, user, pass);
      sentencia = conexion.createStatement();
      // estado="Conectado Correctamente";
    } catch (ClassNotFoundException ex1) {
      ex1.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver");
      estado = "Servidor no esta disponible";
      // System.exit(1);
    } catch (SQLException ex) {
      ex.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(null, "Error Creacion Statement");
      estado = "Servidor no esta disponible";
      // System.exit(1);
    }
    // return estado;
  }
 // AQUI VOYA  OBTENER EL SERVDUIOR QUEMADO EN UN ARCHIVO DE TEXTO
 public void conectarBaseDeDatos2() {
   try {
     final String CONTROLADOR = "org.postgresql.Driver";
     Class.forName(CONTROLADOR);
     // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb";
     conexion = DriverManager.getConnection(url2, user, pass);
     sentencia = conexion.createStatement();
     /*JOptionPane.showMessageDialog(null, "si conecta");*/
   } catch (ClassNotFoundException ex1) {
     // ex1.printStackTrace();
     javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver." + ex1.getMessage());
     System.exit(1);
   } catch (SQLException ex) {
     // ex.printStackTrace();
     javax.swing.JOptionPane.showMessageDialog(
         null,
         "Error Creacion Statement."
             + ex.getMessage()
             + " / "
             + url2
             + " / "
             + user
             + " / "
             + pass);
     System.exit(1);
   }
 }
Exemplo n.º 4
0
  public boolean dbOpenList(Connection connection, String sql) {
    dbClearList();
    this.oldSql = sql;
    this.oldConnection = connection;
    // apre il resultset da abbinare
    ResultSet resu = null;
    ResultSetMetaData meta;
    try {
      stat = connection.createStatement();
      resu = stat.executeQuery(sql);
      meta = resu.getMetaData();

      if (meta.getColumnCount() > 1) {
        this.contieneChiavi = true;
      }

      // righe
      while (resu.next()) {
        for (int i = 1; i <= meta.getColumnCount(); ++i) {
          if (i == 1) {
            dbItems.add((Object) resu.getString(i));
            lm.addElement((Object) resu.getString(i));
          } else if (i == 2) {
            dbItemsK.add((Object) resu.getString(i));

            // debug
            // System.out.println("list:" + String.valueOf(i) + ":" + resu.getString(i));
          } else if (i == 3) {
            dbItemsK2.add((Object) resu.getString(i));
          }
        }
      }
      this.setModel(lm);

      // vado al primo
      if (dbTextAbbinato != null) {
        // debug
        // javax.swing.JOptionPane.showMessageDialog(null,this.getKey(0).toString());
        dbTextAbbinato.setText(this.getKey(0).toString());
      }

      return (true);
    } catch (Exception e) {
      javax.swing.JOptionPane.showMessageDialog(null, e.toString());
      e.printStackTrace();
      return (false);
    } finally {
      try {
        stat.close();
      } catch (Exception e) {
      }
      try {
        resu.close();
      } catch (Exception e) {
      }
      meta = null;
    }
  }
Exemplo n.º 5
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == b) {
     if (makeConnection()) {
       if (!t1.getText().equals("")
           & !t2.getText().equals("")
           & !t3.getText().equals("")
           & !t4.getText().equals("")) {
         det dez = new det();
         if (dez.date(t4.getText())) {
           String a = t1.getText();
           String b = t2.getText();
           String c = t3.getText();
           String d = t4.getText();
           String ef = t5.getText();
           try {
             st = cn.createStatement();
             String sql = "insert into detalle_ventas values('";
             sql += a;
             sql += "', '";
             sql += b + "', '" + c + "', '" + d + "', '" + ef;
             sql += "')";
             int eaz = st.executeUpdate(sql);
             javax.swing.JOptionPane.showMessageDialog(
                 null,
                 "Se han creado " + eaz + " registros en la base de datos",
                 "informacion",
                 javax.swing.JOptionPane.INFORMATION_MESSAGE);
             start();
           } catch (SQLException exz) {
             javax.swing.JOptionPane.showMessageDialog(
                 null,
                 "Ha ocurrido un error, favor de checar que la clave no ha sido ingresada ya con anterioridad  \n si el problema persiste contacte con el administrador \nError: "
                     + exz.getSQLState()
                     + ""
                     + exz.getMessage(),
                 "Error",
                 javax.swing.JOptionPane.INFORMATION_MESSAGE);
           } catch (Exception ez) {
             System.out.println(ez.getMessage());
           }
         } else {
           javax.swing.JOptionPane.showMessageDialog(
               null,
               "Favor de llenar la fecha con un formato correcto dd/mm/aaaa",
               "Error!!!",
               javax.swing.JOptionPane.ERROR_MESSAGE);
         }
       } else {
         javax.swing.JOptionPane.showMessageDialog(
             null,
             "Favor de llenar todos los datos correctamente",
             "Error!!!",
             javax.swing.JOptionPane.ERROR_MESSAGE);
       }
     } else {
       javax.swing.JOptionPane.showMessageDialog(
           null,
           "Un error ha ocurrido al intentar conectar con la base de datos, \n reinicie el componente o contacte con el administrador",
           "Error",
           javax.swing.JOptionPane.ERROR_MESSAGE);
     }
   }
   try {
     cn.close();
   } catch (Exception esa) {
     System.out.println(esa.getMessage());
   }
 }
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String str = "";
    String str1;
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("dd-MM-yyyy");
    String formattedDate = fmt.format(jDateChooser1.getDate());
    if (jRadioButton1.isSelected()) str = jRadioButton1.getText();
    if (jRadioButton2.isSelected()) str = jRadioButton2.getText();
    if (jRadioButton3.isSelected()) str = jRadioButton3.getText();
    if (jRadioButton4.isSelected()) str = jRadioButton4.getText();
    if (jRadioButton5.isSelected()) str = jRadioButton5.getText();
    if (jRadioButton6.isSelected()) str = jRadioButton6.getText();
    /*   if(formattedDate.compareTo(str)==0)
    {
        information.setText("Un booked");
    }
    else
       information.setText(str);*/
    try {
      res = st.executeQuery("select * from Booking where Event_date='" + formattedDate + "'");
      if (res.next()) { // txtroll.setText(res.getString(0));
        // jTextField1.setText(res.getString(6));
        // jTextField1.setText(res.getString(6));
        // jTextField1.setText(res.getString(7));
        str1 = res.getString(7);
        if (formattedDate.compareTo(res.getString(6)) == 0) {
          if (str1.compareTo("A-2") == 0) jRadioButton1.setVisible(false);
          else jRadioButton1.setVisible(true);
          if (str1.compareTo("A-11") == 0) jRadioButton2.setVisible(false);
          else jRadioButton2.setVisible(true);
          if (str1.compareTo("A-12") == 0) jRadioButton3.setVisible(false);
          else jRadioButton3.setVisible(true);
          if (str1.compareTo("A-13") == 0) jRadioButton4.setVisible(false);
          else jRadioButton4.setVisible(true);
          if (str1.compareTo("EEE-Auditorium") == 0) jRadioButton5.setVisible(false);
          else jRadioButton5.setVisible(true);
          if (str1.compareTo("Barn") == 0) jRadioButton6.setVisible(false);
          else jRadioButton6.setVisible(true);
          // repaint();
        }
        // str1=res.getString(6).toString();
        // jTextField1.setText(str1);
        // javax.swing.JOptionPane.showMessageDialog(null,"Invalid.....");
        // jRadioButton3.setVisible(false);

        // txtcontact.setText(res.getString(12));

      } else {
        jRadioButton1.setVisible(true);
        jRadioButton2.setVisible(true);
        jRadioButton3.setVisible(true);
        jRadioButton4.setVisible(true);
        jRadioButton5.setVisible(true);
        jRadioButton6.setVisible(true);
      }
    } catch (Exception e) {
      javax.swing.JOptionPane.showMessageDialog(null, e.toString());
    }
    str1 = formattedDate;
  } // GEN-LAST:event_jButton1ActionPerformed
Exemplo n.º 7
0
  private void create_bottonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_create_bottonActionPerformed
    // TODO add your handling code here:
    try {
      /*
          Connection conn =  DriverManager.getConnection("jdbc:sqlite:C:/Documents and Settings/ishant0/bonafide.db");

         JasperDesign jasperDesign = JRXmlLoader.load("E:\\PD\\pd\\pratice\\Bonafide\\src\\bonafide\\report1.jrxml");
         String name = Second.getcdt();
         //System.out.print(name);
         String sql = "select * from firstInfo order by date DESC LIMIT 1";


         /*java.util.Map parameters = new java.util.HashMap();
         parameters.put("name", name);
         String abc = "Hey now please work properly!!";
         parameters.put("abc", abc);
          *


         JRDesignQuery newQuery = new JRDesignQuery();
         newQuery.setText(sql);
         jasperDesign.setQuery(newQuery);
         JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
         JasperViewer.viewReport(jasperPrint);

      }
      catch (Exception ex)
      {
          JOptionPane.showMessageDialog(null, ex);
      }
       */

      // Commented on 18-june-2013
      /*
        ps = con.prepareStatement("select * from abc"); //Table abc contains formate for certificates..............
        /* now use type table with typeName and formate datafield.....
         *

        rs = ps.executeQuery();
        rs.next();
        String s = rs.getString(1);

            rs.close();
            ps.close();



        st = con.createStatement();
        ResultSet rs2= st.executeQuery("select * from firstInfo order by date desc limit 1");
        rs2.next();
        String name = rs2.getString("name");
        String rollnum = rs2.getString("rollnum");



        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(java.util.regex.Pattern.quote("name??"));
        String data[] = pattern.split(s);
        String o1 = data[0] +" "+name+" "+data[1];

        pattern = java.util.regex.Pattern.compile(java.util.regex.Pattern.quote("roll??"));
        data = pattern.split(o1);
        String op = data[0] +" "+rollnum+" "+data[1];
        //System.out.println(op);

      */

      // NWE CODE:
      // Step-1  Fetching formate from type table.
      try {
        con = Connect.getConnection();

        ps = con.prepareStatement("select formate from type where typeName = 'Student Bonafide'");
        rs = ps.executeQuery();
        if (rs.next()) {
          formate = rs.getString("formate");
        } else {
          javax.swing.JOptionPane.showMessageDialog(
              null, "Internal error formate type or Certificate type not found.");
        }

        Connect.closeConnection(con, ps, rs);
        System.out.println("Step 1 completed!!!");
      } catch (Exception e) {
        javax.swing.JOptionPane.showMessageDialog(null, "Closing rs or ps for step 1" + e);
      }

      // Step-2 Fetching data which is last entered in firstInfo table.
      try {
        con = Connect.getConnection();

        ps = con.prepareStatement("select * from firstInfo order by date desc limit 1");
        java.sql.ResultSet rs2 = ps.executeQuery();
        rs2.next();
        name = rs2.getString("name");
        rollnum = rs2.getString("rollnum");
        father_name = rs2.getString("father_name");
        course = rs2.getString("course");
        semester = rs2.getString("sem");

        // System.out.println(name+rollnum+father_name);
        Connect.closeConnection(con, ps, rs2);
        System.out.println("Step 2 completed!!!");
      } catch (Exception e) {
        javax.swing.JOptionPane.showMessageDialog(null, "Problem in step 2" + e);
      }

      // Step-3 Merging data with formate
      try {
        to_deliver = Connect.splitJoin(formate, "{name}", name);
        to_deliver = Connect.splitJoin(to_deliver, "{roll}", rollnum);
        to_deliver = Connect.splitJoin(to_deliver, "(father}", father_name);
        to_deliver = Connect.splitJoin(to_deliver, "{course}", course);
        to_deliver = Connect.splitJoin(to_deliver, "{semester}", semester);
        System.out.println(to_deliver);
        System.out.println("Step 3 completed!!!");
      } catch (Exception e) {
        javax.swing.JOptionPane.showMessageDialog(null, "Problem while merging!" + e);
      }

      // Sending this above result op to toDeliver table:
      try {
        con = Connect.getConnection();
        ps = con.prepareStatement("insert into toDeliver (op) values(?)");
        ps.setString(1, to_deliver);
        ps.executeUpdate();
        Connect.closeConnection(con, ps, null);
      } catch (Exception e) {
        javax.swing.JOptionPane.showMessageDialog(null, "Problem in delivering data" + e);
      }

      // Now code for jasper reports:
      Connection conn =
          DriverManager.getConnection("jdbc:sqlite:C:/Documents and Settings/ishant0/bonafide.db");
      JasperDesign jasperDesign =
          JRXmlLoader.load("E:\\PD\\pd\\pratice\\Bonafide\\src\\bonafide\\report1.jrxml");
      String sql = "select * from toDeliver order by date DESC LIMIT 1";

      JRDesignQuery newQuery = new JRDesignQuery();
      newQuery.setText(sql);
      jasperDesign.setQuery(newQuery);
      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
      JasperViewer.viewReport(jasperPrint);

      // con.close();

    } catch (Exception e) {
      javax.swing.JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_create_bottonActionPerformed