• JDBC


     1 import java.sql.Connection;
     2 import java.sql.DriverManager;
     3 import java.sql.PreparedStatement;
     4 import java.sql.ResultSet;
     5 import java.sql.SQLException;
     6 
     7 public class JdbcUtil {
     8     
     9     private String driver="oracle.jdbc.driver.OracleDriver";
    10     private String url="jdbc:oracle:thin:@localhost:8080: dbName";
    11     private String username="username";
    12     private String password="password";
    13     
    14     private Connection conn = null;
    15     private PreparedStatement pstmt = null;
    16     private ResultSet rst = null;
    17     
    18     public  UserEntity query(String value){
    19         String sql = "select user_id,user_name,phone from p_m_user where user_id =" + value;
    20         UserEntity user = new UserEntity();
    21         
    22         try {
    23             Class.forName(driver);
    24             conn = DriverManager.getConnection(url, username, password);
    25             pstmt = conn.prepareStatement(sql);
    26             rst = pstmt.executeQuery();
    27             if(rst.next()){
    28                 user.setUser_id(rst.getString("user_id"));
    29                 user.setUser_name(rst.getString("user_name"));
    30                 user.setPhone(rst.getNString("phone"));
    31             }
    32             rst.close();
    33             pstmt.close();
    34             conn.close();
    35         } catch (ClassNotFoundException e) {
    36             // TODO Auto-generated catch block
    37             e.printStackTrace();
    38         } catch(SQLException e2){
    39             e2.printStackTrace();
    40         }
    41         return user;
    42     }
    43   
  • 相关阅读:
    烂泥:高负载均衡学习haproxy之TCP应用
    烂泥:高负载均衡学习haproxy之关键词介绍
    sqlpuls基本命令
    Oracle开机自启动
    centos6.5安装oracle11g_2
    centos7安装图片界面
    centos7安装activemq
    centos7删除自带openjdk
    centos7安装nexus私服2.14
    mysql优化记录
  • 原文地址:https://www.cnblogs.com/unique1319/p/6617313.html
Copyright © 2020-2023  润新知