您的位置:首页 > 博客中心 > 数据库 >

jdbc与数据库Oracle链接的自练习

时间:2022-03-14 01:02

myeclipse里面导入新的项目

右键>import>General>existing...>next>select  root >browse>项目>finish

导jar包

右键>properties>java build path >libraries>ojdbc14-10.2.0.3.jar


获取本机ip地址cmd>ipconfig

ipv4的地址为自己的地址

Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:xe";
String user = "scott";
String password="tiger";
Connection conn = DriverManager.getConnection(url,user,password);

PreparedStatement pstam = conn.prepareStatement("select * from userinfo ");

ResultSet rs = pstam.executeQuery();
while(rs.next()){
System.out.println(rs.getInt("id")+rs.getString("name")+rs.getInt("age"));
}

pstam.close();
conn.close();

热门排行

今日推荐

热门手游