package cn.com.login.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class LoginDao { public String getUserName(String userCode){ Connection con = null; PreparedStatement pre = null; ResultSet result = null; String userName = ""; try { Class.forName("oracle.jdbc.driver.OracleDriver"); //加载Oracle驱动程序 System.out.println("开始尝试连接数据库!"); String url = "jdbc:oracle:" + "thin:@10.10.19.19:1521:db123"; String user = "system"; String password = "scc123456"; con = DriverManager.getConnection(url, user, password); System.out.println("连接成功"); String sql = "select userName from web01_test where userCode = ?"; pre = con.prepareStatement(sql); pre.setString(1, userCode); result = pre.executeQuery(); while (result.next()) { userName = result.getString("userName"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (result != null) { result.close(); } if (pre != null) { pre.close(); } if (con != null) { con.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return userName; } }
文章标题:java连接oracle数据库简单实例
网页URL:/article40/ppoieo.html
成都网站建设公司_创新互联,为您提供标签优化、云服务器、响应式网站、企业建站、面包屑导航、用户体验
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联