您好,登錄后才能下訂單哦!
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; } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。