String url = "jdbc:oracle:thin:@localhost:1521:orcl";
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection(url, "scott", "a");
PreparedStatement ps=con.prepareStatement("select * from subject");
这个是连接oracle数据库代码和执行SQL语句的代码。
PreparedStatement ps=con.prepareStatement("select max(nid) from news");
int nextNid=1;
ResultSet rs=ps.executeQuery();
if(rs.next()){
nextNid=rs.getInt(1)+1;
}
ps=con.prepareStatement("insert into news values(?,?,?,?,?,sysdate,0,?)");
ps.setInt(1,nextNid);
ps.setInt(2, tid);
ps.setString(3, ntitle);
ps.setString(4, nzz);
ps.setString(5, nnr);
ps.setString(6, nzy);
int i=ps.executeUpdate();
if(i>0){
out.print("<script>alert('添加成功');location.href='../admin.jsp'</script>");
}else{
out