jsp连接Oracle8/8i/9i数据库
testoracle.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%
String id=request.getParameter("id");
String name = request.getParameter("name");
String age=request.getParameter("age");
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl为你的数据库的SID
String user="scott";
String password="tiger";
String sql="insert into test values(?,?,?)";
Connection conn= DriverManager.getConnection(url,user,password);
PreparedStatement stmt=conn.prepareStatement(sql);
stmt.setString(1,id);
stmt.setString(2,name);
stmt.setString(3,age);
int n=stmt.executeUpdate();
if(n==1)
{
out.println("插入成功!");
}
stmt.close();
conn.close();
%>
</body>
</html>
[此贴子已经被作者于2006-7-13 14:34:41编辑过]