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()) {
out.println(rs.getString(1));
out.println(rs.getString(2));
}
out.print("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close();
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()) {
out.println(rs.getString(1));
out.println(rs.getString(2));
}
out.print("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close();
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = dataSource.getConnection();
String sql = "select SEQ_PROJECT_PLAN.nextval from dual";
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
rs.next();
String seq = rs.getString(1);
return seq;
} catch(SQLException e){
log("getSeqPlanId",e.toString());
throw new EJBException(e);
}finally{
if(pstmt != null){
try{
pstmt.close();
}catch(Exception ex){
}
}
if(conn != null){
try{
conn.close();
}catch(Exception ex){
}
}
} // end of finally
};
里面有答案,虽然我很菜,这个问题我有答案
database的这个方法可以增加、删除、修改,但是不能执行有返回的sql语句
如select
executeStatement(java.lang.String)
public int executeStatement(String statementString)
Executes the SQL statement specified by the statementString parameter. Use this method to execute arbitrary SQL statements, including DDL, that do not yield a ResultSet.
如果是
String sql="select * from test";
好像是这里-->String sql="select * from test;";
好像是这里-->String sql="select * from test;";
两种都可以的,我一般用前种,呵呵,能少写一个就少写一个.