/**
   * Get Company ID by OrganisationID
   *
   * @param OrgID
   * @return PKCompany
   * @throws SQLException
   * @throws Exception
   */
  public int getCompanyID(int OrgID) throws SQLException, Exception {
    String query = "Select FKCompanyID from tblOrganization WHERE PKOrganization = " + OrgID;

    /*db.openDB();
    Statement stmt = db.con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

    if(rs.next())
    	return rs.getInt(1);*/
    int iCompanyID = 0;
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {

      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iCompanyID = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getCompanyID - " + E);
    } finally {

      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iCompanyID;
  }
示例#2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    PrintWriter pw = null;
    try {

      pw = response.getWriter();
      String name = request.getParameter("myval");

      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection conn =
          DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
      Statement st = conn.createStatement();
      String str = "select * from student where name like %" + name + "%";
      ResultSet rs = st.executeQuery(str);
      while (rs.next()) {
        pw.println(
            rs.getString(1) + " " + rs.getInt(2) + " " + rs.getString(3) + " " + rs.getInt(4));
      }
      conn.close();
    } catch (Exception e) {

      pw.print(e + "");
    }
  }
示例#3
0
 // 创建新表
 public boolean createTable(String tableName) {
   try {
     Connection conn = getConn();
     if (conn != null) {
       StringBuilder sql = new StringBuilder("CREATE TABLE ");
       sql.append(tableName);
       sql.append(" (");
       sql.append("serialno int(11) NOT NULL AUTO_INCREMENT,");
       sql.append("title varchar(128) NOT NULL,");
       sql.append("smalldesc varchar(512) NOT NULL,");
       sql.append("smallurl varchar(256) DEFAULT NULL,");
       sql.append("source varchar(32) NOT NULL,");
       sql.append("releasetime bigint(20) NOT NULL,");
       sql.append("content varchar(128) NOT NULL,");
       sql.append("classify varchar(16) NOT NULL,");
       sql.append("curl varchar(256) NOT NULL,");
       sql.append("createtime varchar(14) NOT NULL,");
       sql.append("PRIMARY KEY (serialno)");
       sql.append(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=gbk");
       PreparedStatement stat = conn.prepareStatement(sql.toString());
       stat.executeUpdate();
       conn.close();
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return true;
 }
  /* goodG2B() - uses goodsource and badsink */
  private void goodG2B() throws Throwable {
    String data;

    /* FIX: Use a hardcoded string */
    data = "foo";

    Connection dbConnection = null;

    try {
      dbConnection = IO.getDBConnection();

      /* POTENTIAL FLAW: Set the catalog name with the value of data
       * allowing a nonexistent catalog name or unauthorized access to a portion of the DB */
      dbConnection.setCatalog(data);
    } catch (SQLException exceptSql) {
      IO.logger.log(Level.WARNING, "Error getting database connection", exceptSql);
    } finally {
      try {
        if (dbConnection != null) {
          dbConnection.close();
        }
      } catch (SQLException exceptSql) {
        IO.logger.log(Level.WARNING, "Error closing Connection", exceptSql);
      }
    }
  }
  /**
   * Updates a registration
   *
   * @param registration The registration to update
   * @return The updated registration
   * @throws Exception
   */
  private Registration upsertRegistrationInternal(Registration registration) throws Exception {
    Connection conn = new Connection(mConnectionString);

    String resource = registration.getURI();
    String content = registration.toXml();

    String response = conn.executeRequest(resource, content, XML_CONTENT_TYPE, "PUT");

    Registration result;
    if (PnsSpecificRegistrationFactory.getInstance().isTemplateRegistration(response)) {
      result =
          PnsSpecificRegistrationFactory.getInstance()
              .createTemplateRegistration(mNotificationHubPath);
    } else {
      result =
          PnsSpecificRegistrationFactory.getInstance()
              .createNativeRegistration(mNotificationHubPath);
    }

    result.loadXml(response, mNotificationHubPath);

    storeRegistrationId(result.getName(), result.getRegistrationId(), registration.getPNSHandle());

    return result;
  }
  /* goodG2B() - use goodsource and badsink */
  public void goodG2BSink(String data) throws Throwable {

    Connection dbConnection = null;
    Statement sqlStatement = null;

    try {
      dbConnection = IO.getDBConnection();
      sqlStatement = dbConnection.createStatement();

      /* POTENTIAL FLAW: data concatenated into SQL statement used in executeUpdate(), which could result in SQL Injection */
      int rowCount =
          sqlStatement.executeUpdate(
              "insert into users (status) values ('updated') where name='" + data + "'");

      IO.writeLine("Updated " + rowCount + " rows successfully.");
    } catch (SQLException exceptSql) {
      IO.logger.log(Level.WARNING, "Error getting database connection", exceptSql);
    } finally {
      try {
        if (sqlStatement != null) {
          sqlStatement.close();
        }
      } catch (SQLException exceptSql) {
        IO.logger.log(Level.WARNING, "Error closing Statement", exceptSql);
      }

      try {
        if (dbConnection != null) {
          dbConnection.close();
        }
      } catch (SQLException exceptSql) {
        IO.logger.log(Level.WARNING, "Error closing Connection", exceptSql);
      }
    }
  }
  public DigitalLibraryServer() {
    try {
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL, "localhost");

      InitialContext jndi = new InitialContext(properties);
      ConnectionFactory conFactory = (ConnectionFactory) jndi.lookup("XAConnectionFactory");
      connection = conFactory.createConnection();

      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      try {
        counterTopic = (Topic) jndi.lookup("counterTopic");
      } catch (NamingException NE1) {
        System.out.println("NamingException: " + NE1 + " : Continuing anyway...");
      }

      if (null == counterTopic) {
        counterTopic = session.createTopic("counterTopic");
        jndi.bind("counterTopic", counterTopic);
      }

      consumer = session.createConsumer(counterTopic);
      consumer.setMessageListener(this);
      System.out.println("Server started waiting for client requests");
      connection.start();
    } catch (NamingException NE) {
      System.out.println("Naming Exception: " + NE);
    } catch (JMSException JMSE) {
      System.out.println("JMS Exception: " + JMSE);
      JMSE.printStackTrace();
    }
  }
示例#8
0
  public void addPasswordToDataBase(String password, int iD) {
    Connection koneksi = null;
    PreparedStatement pstmt = null;
    String str = "";
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      koneksi =
          DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
      System.out.println("I am Here " + koneksi);

      String sql = "INSERT INTO loginPass(" + "iD," + "passWord) " + "VALUES(?,?)";

      pstmt = koneksi.prepareStatement(sql);
      pstmt.setInt(1, iD);
      pstmt.setString(2, password);
      pstmt.executeUpdate();
      System.out.println("Hello");

      koneksi.close();
    } catch (SQLException sqle) {
      str = "SQLException error";
    } catch (ClassNotFoundException cnfe) {
      str = "ClassNotFoundException error";
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
  }
示例#9
0
  public int getPrimaryID(String userName) {

    Connection koneksi = null;
    Statement stat = null;
    String str = "";
    int iD = 0;
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      koneksi =
          DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
      System.out.println(koneksi);
      stat = koneksi.createStatement();
      ResultSet hasil =
          stat.executeQuery("SELECT iD FROM loginInfo where userName='" + userName + "'");
      if (hasil.next()) iD = hasil.getInt(1);

      stat.close();
      koneksi.close();
    } catch (SQLException sqle) {
      str = "SQLException error";
    } catch (ClassNotFoundException cnfe) {
      str = "ClassNotFoundException error";
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    System.out.println(str);
    return iD;
  }
示例#10
0
 public String selectionQuery() {
   Connection koneksi = null;
   Statement stat = null;
   String str = "";
   try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     koneksi =
         DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
     System.out.println(koneksi);
     stat = koneksi.createStatement();
     ResultSet hasil = stat.executeQuery("SELECT * FROM loginInfo");
     while (hasil.next()) {
       str = str + (hasil.getString(1)) + hasil.getString(2);
     }
     stat.close();
     koneksi.close();
   } catch (SQLException sqle) {
     str = "SQLException error";
   } catch (ClassNotFoundException cnfe) {
     str = "ClassNotFoundException error";
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   return str;
 }
示例#11
0
  public String checkUserOrEmailexit(String userName, String email) {
    Connection koneksi = null;
    Statement stat = null;
    String str = "Accepted";
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      koneksi =
          DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
      System.out.println(koneksi);
      stat = koneksi.createStatement();
      ResultSet hasil =
          stat.executeQuery(
              "SELECT userName, emailID  FROM loginInfo WHERE userName='"
                  + userName
                  + "' OR emailID='"
                  + email
                  + "';");
      if (hasil.next()) str = "Rejected";
      stat.close();
      koneksi.close();
    } catch (SQLException sqle) {
      str = "SQLException error";
    } catch (ClassNotFoundException cnfe) {
      str = "ClassNotFoundException error";
    } catch (InstantiationException e) {
      e.printStackTrace();

    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    return str;
  }
  /**
   * *************************************************** Utility method to remove the tables and
   * allow the user to reset the database for a new season
   *
   * @param conn Connection to the database **************************************************
   */
  public static void beginNewSeason(Connection conn) {
    try {

      Statement stmt = conn.createStatement();

      // remove tables if database tables have been created
      // this will throw an exception if the tables do not exist
      stmt.execute("DROP TABLE Games");
      System.out.println("DROP TABLE Games");
    } catch (Exception ex) {
      // call the method to create tables for the database
      System.out.println("DROP TABLE Games failed");
    }

    try {

      Statement stmt = conn.createStatement();

      // remove tables if database tables have been created
      // this will throw an exception if the tables do not exist
      stmt.execute("DROP TABLE Teams");

      System.out.println("DROP TABLE Teams");
    } catch (Exception ex) {
      // call the method to create tables for the database
      System.out.println("DROP TABLE Teams failed");
    }

    createTeamDB(conn);
  }
示例#13
0
  /**
   * Get organisation's nomination rater status
   *
   * @param iOrgID
   * @return
   * @throws SQLException
   * @throws Exception
   * @author Desmond
   */
  public boolean getNomRater(int iOrgID) throws SQLException, Exception {
    String query = "SELECT NominationModule FROM tblOrganization WHERE PKOrganization =" + iOrgID;
    boolean iNomRater = true;

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iNomRater = rs.getBoolean(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getNomRater - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iNomRater;
  } // End getNomRater()
示例#14
0
  /**
   * Get organisation's name sequence
   *
   * @param iOrgID
   * @return
   * @throws SQLException
   * @throws Exception
   * @author Maruli
   */
  public int getNameSeq(int iOrgID) throws SQLException, Exception {
    String query = "SELECT NameSequence FROM tblOrganization WHERE PKOrganization =" + iOrgID;
    int iNameSeqe = 0;

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iNameSeqe = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getNameSeq - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iNameSeqe;
  }
示例#15
0
  /* to search the DB table for req. video*/
  boolean search(String file) {

    boolean found = false;

    Connection con = null;
    String url =
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};  DBQ=D://db.mdb; DriverID=22;READONLY=true;";

    try {
      con = DriverManager.getConnection(url, "", "");
      try {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT video FROM p3");
        while (rs.next()) {
          String colvalue = rs.getString("video");
          if (colvalue.equalsIgnoreCase(file)) found = true;
        }

      } catch (SQLException s) {
        System.out.println("SQL statement is not executed!");
      }
    } catch (Exception e) {
      System.out.println(e);
    }
    return found;
  }
示例#16
0
  /**
   * Method called by the Form panel to delete existing data.
   *
   * @param persistentObject value object to delete
   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is
   *     successfully completed
   */
  public Response deleteRecord(ValueObject persistentObject) throws Exception {
    PreparedStatement stmt = null;
    try {
      EmpVO vo = (EmpVO) persistentObject;

      // delete from WORKING_DAYS...
      stmt = conn.prepareStatement("delete from WORKING_DAYS where EMP_CODE=?");
      stmt.setString(1, vo.getEmpCode());
      stmt.execute();
      stmt.close();

      // delete from EMP...
      stmt = conn.prepareStatement("delete from EMP where EMP_CODE=?");
      stmt.setString(1, vo.getEmpCode());
      stmt.execute();
      gridFrame.reloadData();

      frame.getGrid().clearData();

      return new VOResponse(vo);
    } catch (SQLException ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    } finally {
      try {
        stmt.close();
        conn.commit();
      } catch (SQLException ex1) {
      }
    }
  }
示例#17
0
  public static void main(String args[]) {
    int myport = 9090;
    Socket s;
    ServerSocket ss;
    BufferedReader fromSoc, fromKbd;
    PrintStream toSoc;
    String line, msg;
    try {
      s = new Socket("169.254.63.10", 6016);
      System.out.println("enter line");
      System.out.println("connected");
      toSoc = new PrintStream(s.getOutputStream());

      toSoc.println(myport);
      String url =
          "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=D://db.mdb; DriverID=22;READONLY=true;";

      Connection con = DriverManager.getConnection(url, "", "");
      Statement st = con.createStatement();
      String ip = "169.254.63.10";
      int port = 6016;
      String video = "rooney";

      st.executeUpdate(
          " insert into p3 values('" + ip + "' , '" + port + "' , '" + video + "' );  ");

      fun();

    } catch (Exception e) {

      System.out.println("exception" + e);
    }
  }
示例#18
0
  public EquiposDB() {
    c = null;
    stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Equipos", "root", "camilo");
      System.out.println("Conectado a Equipo.db");

      stmt = c.createStatement();
      String sql =
          "CREATE TABLE IF NOT EXISTS Equipos"
              + "(ID INT NOT NULL AUTO_INCREMENT,"
              + " Nombre TEXT NOT NULL, "
              + " Formacion TEXT,"
              + " Arquero INT, "
              + " Defensor INT, "
              + " Mediocampo INT, "
              + " Ataque INT, "
              + " PRIMARY KEY(ID))";
      stmt.executeUpdate(sql);
      stmt.close();
      c.close();
    } catch (ClassNotFoundException | SQLException e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    System.out.println("Tabla " + nteam + " creada");
  }
示例#19
0
 public void save() {
   try (Connection con = DB.sql2o.open()) {
     String sql = "INSERT INTO categories (name) VALUES (:name)";
     this.id =
         (int) con.createQuery(sql, true).addParameter("name", this.name).executeUpdate().getKey();
   }
 }
示例#20
0
 public ArrayList<String> getEquipos() throws SQLException, ClassNotFoundException {
   ArrayList<String> foo = new ArrayList();
   Class.forName("org.sqlite.JDBC");
   c = DriverManager.getConnection("jdbc:sqlite:Equipos.db");
   c.setAutoCommit(false);
   System.out.println("Tabla Equipos abierta");
   stmt = c.createStatement();
   try (ResultSet rs = stmt.executeQuery("SELECT Nombre FROM Equipos;")) {
     while (rs.next()) {
       int id = rs.getInt("id");
       String name = rs.getString("Nombre");
       String form = rs.getString("Formacion");
       int h1 = rs.getInt("Arquero");
       int h2 = rs.getInt("Defensor");
       int h3 = rs.getInt("Mediocampo");
       int h4 = rs.getInt("Ataque");
       foo.add(Integer.toString(id));
       foo.add(name);
       foo.add(form);
       foo.add(Integer.toString(h1));
       foo.add(Integer.toString(h2));
       foo.add(Integer.toString(h3));
       foo.add(Integer.toString(h4));
     }
   }
   stmt.close();
   c.close();
   System.out.println("Operation done successfully");
   return foo;
 }
  /* uses badsource and badsink */
  public void bad() throws Throwable {
    String data;

    /* get system property user.home */
    /* POTENTIAL FLAW: Read data from a system property */
    data = System.getProperty("user.home");

    Connection dbConnection = null;

    try {
      dbConnection = IO.getDBConnection();

      /* POTENTIAL FLAW: Set the catalog name with the value of data
       * allowing a nonexistent catalog name or unauthorized access to a portion of the DB */
      dbConnection.setCatalog(data);
    } catch (SQLException exceptSql) {
      IO.logger.log(Level.WARNING, "Error getting database connection", exceptSql);
    } finally {
      try {
        if (dbConnection != null) {
          dbConnection.close();
        }
      } catch (SQLException exceptSql) {
        IO.logger.log(Level.WARNING, "Error closing Connection", exceptSql);
      }
    }
  }
示例#22
0
  public Boolean insertarEquipo(String name, String form, int h1, int h2, int h3, int h4)
      throws ClassNotFoundException, SQLException {

    Connection c = null;
    Statement stmt = null;
    Boolean boo = true;
    try {
      // for (int d = 2; d < 20; d++) {
      ///    asd();
      //  }

      System.out.println(cont);
      Class.forName("com.mysql.jdbc.Driver");
      c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Equipos", "root", "camilo");
      c.setAutoCommit(false);
      stmt = c.createStatement();
      String sql =
          "INSERT INTO Equipos (Nombre,Formacion,Arquero,Defensor,Mediocampo,Ataque) "
              + String.format("VALUES ('%s','%s',%2d,%2d,%2d,%2d);", name, form, h1, h2, h3, h4);
      stmt.executeUpdate(sql);
      cont++;
      System.out.println("Equipo insertado ");
      stmt.close();
      c.commit();
      c.close();
    } catch (Exception e) {
      System.out.println("Error en insertarEquipo");
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    return boo;
  }
  public Nutzer insert(Nutzer a) {
    Connection con = DBConnection.connection();
    try {
      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT MAX(NutzerId) AS maxid " + "FROM nutzer");

      if (rs.next()) {
        a.setId(rs.getInt("maxid") + 1);

        stmt = con.createStatement();

        stmt.executeUpdate(
            "INSERT INTO nutzer (NutzerId, Email, Vorname, Nachname, Passwort)"
                + "VALUES ("
                + a.getId()
                + ",'"
                + a.getEmail()
                + "','"
                + a.getVorname()
                + "','"
                + a.getNachname()
                + "','"
                + a.getPassword()
                + "')");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return a;
  }
 public CFSecurityTSecGroupBuff lockBuff(
     CFSecurityAuthorization Authorization, CFSecurityTSecGroupPKey PKey) {
   final String S_ProcName = "lockBuff";
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     long TenantId = PKey.getRequiredTenantId();
     int TSecGroupId = PKey.getRequiredTSecGroupId();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_lock_tsecgrp( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     if (stmtLockBuffByPKey == null) {
       stmtLockBuffByPKey = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtLockBuffByPKey.setLong(argIdx++, TenantId);
     stmtLockBuffByPKey.setInt(argIdx++, TSecGroupId);
     resultSet = stmtLockBuffByPKey.executeQuery();
     if (resultSet.next()) {
       CFSecurityTSecGroupBuff buff = unpackTSecGroupResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       return (buff);
     } else {
       return (null);
     }
   } catch (SQLException e) {
     throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
   } finally {
     if (resultSet != null) {
       try {
         resultSet.close();
       } catch (SQLException e) {
       }
       resultSet = null;
     }
   }
 }
 public void updateName(String new_name) {
   this.name = new_name;
   String sql = "UPDATE clients SET name = :name WHERE id = :id;";
   try (Connection con = DB.sql2o.open()) {
     con.createQuery(sql).addParameter("name", name).addParameter("id", id).executeUpdate();
   }
 }
示例#26
0
  /** Creates new form PrincipalCliente */
  public ModificarAdmin() {
    initComponents();
    conexioninicio ci = new conexioninicio();
    ci.conectar();
    this.setSize(470, 650);
    this.setLocationRelativeTo(null); // Centra la ventana Splash
    try {
      Connection con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      //  System.out.println("Conexion a la base de datos cliente realizada con exito! ");
      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT * FROM tienda.estado ;");
      // obteniendo la informacion de las columnas que estan siendo consultadas
      ResultSetMetaData rsMd = rs.getMetaData();
      // La cantidad de columnas que tiene la consulta
      int cantidadColumnas = rsMd.getColumnCount();
      // Establecer como cabezeras el nombre de las columnas

      // Creando las filas para el Jtable
      while (rs.next()) {
        Object[] fila = new Object[cantidadColumnas];
        for (int i = 1; i < cantidadColumnas; i++) {
          jComboBox1.addItem(rs.getObject(i + 1));
        }
      }
      rs.close();
      con.close();

    } catch (Exception e) {

      JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
 private void handleKeepAlive() {
   Connection c = null;
   try {
     netCode = ois.readInt();
     c = checkConnectionNetCode();
     if (c != null && c.getState() == Connection.STATE_CONNECTED) {
       oos.writeInt(ACK_KEEP_ALIVE);
       oos.flush();
       System.out.println("->ACK_KEEP_ALIVE"); // $NON-NLS-1$
     } else {
       System.out.println("->NOT_CONNECTED"); // $NON-NLS-1$
       oos.writeInt(NOT_CONNECTED);
       oos.flush();
     }
   } catch (IOException e) {
     System.out.println("handleKeepAlive: " + e.getMessage()); // $NON-NLS-1$
     if (c != null) {
       c.setState(Connection.STATE_DISCONNECTED);
       System.out.println(
           "Connection closed with "
               + c.getRemoteAddress()
               + //$NON-NLS-1$
               ":"
               + c.getRemotePort()); // $NON-NLS-1$
     }
   }
 }
示例#28
0
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    conexioninicio ci = new conexioninicio();
    Connection con = null;

    try {
      Class.forName("org.gjt.mm.mysql.Driver");
      con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      Statement stmt = con.createStatement();
      String cadenasql =
          "select nombre,apPat,apMat,calle,numExt,colonia,municipio,cp,email,numTel,curp,idadmon,contraseña,nombreest from persona natural join admin natural join estado where idadmon="
              + "'"
              + User
              + "'";
      ResultSet rs = stmt.executeQuery(cadenasql);
      while (rs.next()) {
        nombre.setText(rs.getString("nombre"));
        apPat.setText(rs.getString("apPat"));
        apMat.setText(rs.getString("apMat"));
        calle.setText(rs.getString("calle"));
        num.setText(rs.getString("numExt"));
        colonia.setText(rs.getString("colonia"));
        municipio.setText(rs.getString("municipio"));
        cp.setText(rs.getString("cp"));
        email.setText(rs.getString("email"));
        telefono.setText(rs.getString("numTel"));
        curp.setText(rs.getString("curp"));
        idamin.setText(rs.getString("idadmon"));
        contraseñaactual.setText(rs.getString("contraseña"));
        this.jComboBox1.setSelectedItem(rs.getString("nombreest"));
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } // TODO add your handling code here:
  } // GEN-LAST:event_jButton1ActionPerformed
示例#29
0
  public void connectToTE(
      TileEntityLittleTiles te, ForgeDirection direction, LittleTileBox cableBox) {
    for (int i = 0; i < te.tiles.size(); i++) {
      if (te.tiles.get(i) instanceof LittleTileTileEntity
          && te.tiles.get(i) != this
          && te.tiles.get(i).boundingBoxes.size() > 0
          && (((LittleTileTileEntity) te.tiles.get(i)).tileEntity instanceof EnergyCable
              || ((LittleTileTileEntity) te.tiles.get(i)).tileEntity instanceof EnergyComponent)) {
        LittleTileBox box = te.tiles.get(i).boundingBoxes.get(0).copy();
        if (direction != null) {
          ChunkCoordinates coord = new ChunkCoordinates(te.xCoord, te.yCoord, te.zCoord);
          // RotationUtils.applyDirection(direction, coord);

          box.applyDirection(direction);

          ForgeDirection side = cableBox.faceTo(box);
          if (side != ForgeDirection.UNKNOWN) {
            Connection otherSide =
                new Connection(
                    new ChunkCoordinates(this.te.xCoord, this.te.yCoord, this.te.zCoord), null);
            LittleTileBox otherBox =
                otherSide.getConnectionBox(
                    te.tiles.get(i).cornerVec.copy(), direction.getOpposite());
            if (te.isSpaceForLittleTile(otherBox.getBox(), te.tiles.get(i)))
              overrrideConnection(
                  direction, new Connection(coord, te.tiles.get(i).cornerVec.copy()));
          }
        } else {
          ForgeDirection side = cableBox.faceTo(box);
          if (side != ForgeDirection.UNKNOWN)
            overrrideConnection(side, new Connection(null, te.tiles.get(i).cornerVec.copy()));
        }
      }
    }
  }
示例#30
0
  /** Get Organisation ID by User email */
  public int getOrgIDbyEmail(String UserEmail) throws SQLException, Exception {
    String query = "Select COUNT(*) as TotRecord from tblEmail";
    int count = 0;
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        count = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - editRecord - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return count;
  }