1.加载MySql的驱动类
Class.forName("com.mysql.jdbc.Driver") ;
2.创建数据库的连接
Connection conn = DriverMananger.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","用户名","密码");
3. 执行查询
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from dept");
while(rs.next()){
System.out.println("deptno"+rs.getInt(1));
System.out.println(" Dname: "+rs.getString(2));
System.out.println(" Loc: "+rs.getString(3));
}
4. 关闭数据库连接
rs.close();
stmt.close();
conn.close();