java连接Oracle数据库
方式一:采用JDBC-ODBC Bridge连接oracle数据库
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection ct=DriverManager.getConnection("jdbc:odbc:XXXX","scott","orcl");
Statement sm=ct.createStatement();
ResultSet rs=sm.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("用户名: "+rs.getString(2));
}
}
catch(Exception e)
{
e.printStackTrace();
}
方式二:jdbc的thin方式
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL","scott","orcl");
Statement sm=ct.createStatement();
ResultSet rs=sm.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("用户名: "+rs.getString(2));
}
}
catch(Exception e)
{
e.printStackTrace();
}