package cn.com.login.dao; import java.sql.Connection; import java.sql.DriverManager; im
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;
}
}
--结束END--
本文标题: java连接oracle数据库简单实例
本文链接: https://lsjlt.com/news/39042.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0