日期:2014-05-16  浏览次数:20386 次

Myeclipse6.0连接Oracle10g数据库实例源码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class oracle {
public static final String OracleDriverName="oracle.jdbc.driver.OracleDriver";
public static void main(String []args)
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String oracleUrlToConnect="jdbc:oracle:thin:@localhost:1521:db";
String user="admin";
String password="a126";
Connection myConnection=DriverManager.getConnection(oracleUrlToConnect,user,password);
Statement st=myConnection.createStatement();
ResultSet rs=st.executeQuery("select * from users");
while(rs.next())
{
System.out.println(rs.getString(1));
}
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getStackTrace());
}
}
}