Package com.mysql.jdbc

Examples of com.mysql.jdbc.Statement


    }
   
    public ResultSet selectQuery( String sqlStatement ) {
        System.out.println( sqlStatement );
        try {
            Statement stmt = ( Statement ) connection.getConnection().createStatement();

            return stmt.executeQuery( sqlStatement );
        } catch( SQLException e ) {
            System.out.println( e.getMessage() );
            throw new RuntimeException();
        }
    }
View Full Code Here


        int affectedRows = 0;

        System.out.println( sqlStatement );

        try {
            Statement stmt = ( Statement ) connection.getConnection().createStatement();
            affectedRows = stmt.executeUpdate( sqlStatement );
        } catch( SQLException e ) {
            System.out.println( e.getMessage() );
            throw new RuntimeException();
        }
View Full Code Here

    public static void main(String args[]) {
        DbUtility conn = new DbUtility();
        try {
            String query = "select * from pemilikkos";
            Statement statement = (Statement) conn.getConnection().createStatement();
            ResultSet result = statement.executeQuery(query);

            while (result.next()) {
                System.out.println("userName : " + result.getString("idpemilik"));
                System.out.println("Password  : " + result.getString("password"));
              
            }
            statement.close();
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }

    }
View Full Code Here

        }
    }

    void executeStatement(String command){
        try {
            Statement statement = (Statement) conn.createStatement();
            synchronized(mutex){
                /* Even if execute is a synchronized method we want
                 * this mutex variable to sinchronize execute with other
                 * atomic code blocks (outside dbConnector).
                 *
                 */
                statement.execute(command);
            }
            statement.close();
        } catch (SQLException ex) {
            Log4k.error(dbConnector.class.getName(),
                    ex.getMessage() + "\n\tcommand was " + command);
        }
    }
View Full Code Here

     * It must be used within a synchronized context, wherein locking a variable
     * would cause a deadlock.
     */
    void executeStatementNoLock(String command){
        try {
            Statement statement = (Statement) conn.createStatement();
            statement.execute(command);
            statement.close();
        } catch (SQLException ex) {
            Log4k.error(dbConnector.class.getName(),
                    ex.getMessage() + "\n\tcommand was " + command);
        }
    }
View Full Code Here

    }
   
    ResultSet executeQuery(String query){
        ResultSet res = null;
        try {
            Statement statement = (Statement) conn.createStatement();
            res = (ResultSet) statement.executeQuery(query);
            /* we must not close the statement here, otherwise res drops */
        } catch (SQLException ex) {
            Log4k.error(dbConnector.class.getName(),
                    ex.getMessage() + "\n\tquery was " + query);
        }
View Full Code Here

   
  }
 
  private void executeQuery(String query){
    try {
      Statement state = (Statement) con.createStatement();
      state.executeUpdate(query);
     
      state.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

  private ArrayList<String> executeQuery(String query, int col){
    ArrayList<String> resReturn = new ArrayList<String>();
   
    try {
      ResultSet result;
      Statement state = (Statement) con.createStatement();
      result = state.executeQuery(query);
     
      while(result.next()){
        resReturn.add(result.getString(col));
      }
     
      state.close();
      result.close();
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    }
View Full Code Here

*/
  public  boolean excSql(String sql) { 
  if(con == null)getConnection(); //连接到数据库  
 
     try
        Statement st = (Statement) con.createStatement();    // 创建用于执行静态sql语句的Statement对象  
           int counts=st.executeUpdate(sql)// 执行操作的sql语句  
           if (0==counts) {
          log.info("执行成功,,共0条数据受到影响,没有完成操作!:SQL语句-->【"+sql+"】");
      return false;
           }
           log.info("执行成功,共"+counts+"条数据受到影响:"+"SQL语句-->【"+sql+"】");
View Full Code Here

  public  ResultSet querySql(String sql) { 
         
      ResultSet rs=null;
      if(con == null)getConnection(); //连接到数据库  
          try
            Statement st = null;   //创建用于执行静态sql语句的Statement对象,st属局部变量  
            st=(Statement) con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
              rs = st.executeQuery(sql);    //执行sql查询语句,返回查询数据的结果集              
              log.info("执行成功:SQL查询语句-->【"+sql+"】");
          }       
            catch (SQLException e) { 
              log.error("执行失败:SQL查询语句-->【"+sql+"】");
              log.error(e.getMessage());
View Full Code Here

TOP

Related Classes of com.mysql.jdbc.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.