try{
String driver="jdbc.oracle.driver.OracleDriver"; //数据驱动
String url="oracle:jdbc:thin:@127.0.0.1:1521:ORCL";//本机数据库url
String username="demo"; //数据库用户名
String pwd="demo";//密码
Class.forName(driver); //加载驱动
Connection con=DriverManager.getConnection(url,username,pwd); //获取连接
PreparedStatement ps=con.prepareStatement("select *from users"); //获取PreparedStatement对象
System.out.println(rs.getInt(1));
}
}catch(Exception e){
e.printStackTrace();
}
String driver="jdbc.oracle.driver.OracleDriver"; //数据驱动
String url="oracle:jdbc:thin:@127.0.0.1:1521:ORCL";//本机数据库url
String username="demo"; //数据库用户名
String pwd="demo";//密码
Class.forName(driver); //加载驱动
Connection con=DriverManager.getConnection(url,username,pwd); //获取连接
PreparedStatement ps=con.prepareStatement("select *from users"); //获取PreparedStatement对象
ResultSet rs=ps.executeQuery();//执行查询
//循环结果
while(rs.next()){System.out.println(rs.getInt(1));
}
}catch(Exception e){
e.printStackTrace();
}