答案:<%@ page contentType="text/html; charset=GBK" %>
<%@ 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>
上一个:Weblogic 下调试servlet
下一个:jsp调用Entity Bean的例子