连接基本如此:
Connection connection = null;
try{
//Load JDBC:
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);//create a connection to the database:
String serverName = "128.0.0.1";
String portNumber = "1521";
String sid = "mydata";
String url = "jdbc:oracle:thin:@"+serverName+":"+portNumber+":"+sid;
String username = "laodie";
String password = "911";
connection = DriverManager.getConnection(url,username,password);}catch(ClassNotFoundException e){
//
}catch(SQLException e){
//
}使用命令的话:
Statement smt = connection.createStatement();
String orcetc="查询语句";
smt.executeUpdate(orcetc);

解决方案 »

  1.   

    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为你的数据库的SID String user="scott"; String password="tiger"; Connection conn= DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from test"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {% > 您的第一个字段内容为:< %=rs.getString(1)% > 您的第二个字段内容为:< %=rs.getString(2)% > < %}% > < %out.print("数据库操作成功,恭喜你");% > < %rs.close(); stmt.close(); conn.close();