欢迎光临
我们一直在努力

weblogic 下 jsp 连接数据库的例(使用JDNI)-JSP教程,资料/其它

建站超值云服务器,限时71元/月

<%@ 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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » weblogic 下 jsp 连接数据库的例(使用JDNI)-JSP教程,资料/其它
分享到: 更多 (0)