<%@ page import="java.sql.*";
page import="java.io.IOException ",
page import="javax.naming.Context ",
page import="javax.naming.InitialContext ",
page import="javax.sql.DataSource " %>
<%!
java.sql.Connection conn;
Statement stmt=null;
java.sql.ResultSet rs=null;
int flag=0;
javax.sql.DataSource ds=null;
public void jspInit(){
try{
javax.naming.InitialContext initx = new javax.naming.InitialContext();
ds = (javax.sql.DataSource )initx.lookup("TestJndi") ;//JNDIName
conn = ds.getConnection() ;
}
catch(Exception ea){
}
}
%>
<html>
<head>
<title>
Jsp1
</title>
</head>
<body>
<%
stmt=conn.createStatement() ;
rs =stmt.executeQuery("select * from province") ;
if (rs==null){
out.print("rs is null");
}
while(rs.next() ){
out.print(rs.getString("province_name")) ;
}
%>
<h1>
JBuilder Generated JSP
</h1>
<form method="post">
<br>Enter new value : <input name="sample"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
</form>
</body>
</html>
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/