//DbUtil
public static Connection getConnection(){
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//构建数据库连接
// String url="jdbc:oracle:thin:@166.111.5.117:1521:o8i1";
// String uid="stu50";
// String pwd="stu50";
String url="jdbc:oracle:thin:@192.168.42.128:1521:orcl";
String uid="studsys";
String pwd="orcl";
Connection conn=DriverManager.getConnection(url,uid,pwd);
Log.getLog().info("数据库连接成功!!!");
return conn;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//JDBC
UserRegPO getUser(String userId){
Connection conn=null;
try{
String sql="select * from user_reg where user_id=?";
conn=(Connection) DbUtil.getConnection();
PreparedStatement pstmt=((java.sql.Connection) conn).prepareStatement(sql);
pstmt.setString(1,userId);
ResultSet rs=pstmt.executeQuery();
UserRegPO user=null;
if(rs.next()){
user= new UserRegPO();
String name=rs.getString("name");
String password=rs.getString("password");
String userType=rs.getString("user_type");
user.setUserId(userId);
user.setName(name);
user.setPassword(password);
user.setUserType(userType);
}
rs.close();
pstmt.close();
return user;
}catch (Exception e) {
e.printStackTrace();
}finally{
conn.close();
}
return null;
}
public static void main(String[] args) {
UserRegDAO dao=new UserRegDAO();
UserRegPO user=dao.getUser("lixin");
Log.getLog().info(
",userId="+user.getUserId()+
",name="+user.getName()+
",password="+user.getPassword()+
",userType="+user.getUserType()
);
}
}
public static Connection getConnection(){
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//构建数据库连接
// String url="jdbc:oracle:thin:@166.111.5.117:1521:o8i1";
// String uid="stu50";
// String pwd="stu50";
String url="jdbc:oracle:thin:@192.168.42.128:1521:orcl";
String uid="studsys";
String pwd="orcl";
Connection conn=DriverManager.getConnection(url,uid,pwd);
Log.getLog().info("数据库连接成功!!!");
return conn;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//JDBC
UserRegPO getUser(String userId){
Connection conn=null;
try{
String sql="select * from user_reg where user_id=?";
conn=(Connection) DbUtil.getConnection();
PreparedStatement pstmt=((java.sql.Connection) conn).prepareStatement(sql);
pstmt.setString(1,userId);
ResultSet rs=pstmt.executeQuery();
UserRegPO user=null;
if(rs.next()){
user= new UserRegPO();
String name=rs.getString("name");
String password=rs.getString("password");
String userType=rs.getString("user_type");
user.setUserId(userId);
user.setName(name);
user.setPassword(password);
user.setUserType(userType);
}
rs.close();
pstmt.close();
return user;
}catch (Exception e) {
e.printStackTrace();
}finally{
conn.close();
}
return null;
}
public static void main(String[] args) {
UserRegDAO dao=new UserRegDAO();
UserRegPO user=dao.getUser("lixin");
Log.getLog().info(
",userId="+user.getUserId()+
",name="+user.getName()+
",password="+user.getPassword()+
",userType="+user.getUserType()
);
}
}
解决方案 »
- 当查询视图带 Where 条件 时,可会自动优化?
- 数据库父子关系的疑问?
- 当ORACLE与SQLSERVER2005中存在一个结构完全相同的表,在JAVA中如何实现当更新sqlserver2005中的表时同时也更新ORACLE中的表,请各位大侠们帮忙!
- trigger自动更新问题
- 客户端需要怎样的条件才能执行SQL/PLUS?
- 问如何将一个字符串中指定位置的字符替换成我要需要的
- EXP时出现问题,请大家帮忙!
- 求各位大侠帮我看一下这个!!!(proc)
- 请问怎样搜索到某字段值与当前系统时间相差5分钟的的纪录?
- 请问各位高手:关于建库后的几个疑点!
- 如何判断游标中有没有记录!
- 急救 Oracle UCM 安装
那么虚拟机的网卡模式要配成桥接模式
检查一下你电脑的tns服务开启了没有就是远程连接服务。。