create table test(test1 varchar(20),test2 varchar(20)
Then write a test record to this table. Now let's start our jsp and database journey.
testoracle.jsp is as follows:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl is the SID of your database
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()) {%>
Your first field content is: <%=rs.getString(1)%>
Your second field content is: <%=rs.getString(2)%>
<%}%>
<%out.print("Database operation successful!");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
Redirect to: http://www.cnjsp.org