文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个简单数据库连接的javabean

一个简单数据库连接的javabean

时间:2006-12-22  来源:kvsg_yang

DBConnection.java package ConnectionDB; import java.sql.*;
public class DBConnection
{
private String driver;
private StringBuffer accessURL;
private String accessFileName;
private String accessFilePath;
private Connection conn;
public DBConnection()
{
driver="sun.jdbc.odbc.JdbcOdbcDriver";
accessURL=new StringBuffer("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=");
accessFilePath="";
accessFileName="";
conn=null;
}
public Connection getConnectionToAccess(String s)throws SQLException,ClassNotFoundException{
accessURL.append(s);
Class.forName(driver);
conn=DriverManager.getConnection(accessURL.toString());
return conn;
}
public void close()
{
try{
conn.close();
   }
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
}
}
    test.jsp <%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<jsp:useBean id="DBConnection" scope="page" class="ConnectionDB.DBConnection"/>
<%
  Connection conn=DBConnection.getConnectionToAccess(application.getRealPath("data/guestbook.mdb"));
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
%>
<%
  String sql="select * from Guestbook order by id DESC";
  ResultSet Rs=stmt.executeQuery(sql);
  while(Rs.next()) {%>  
  您的第一个字段内容为:<%=Rs.getString(1)%>  
  您的第二个字段内容为:<%=Rs.getString(2)%>  
  <%}%>  
  <%out.print("数据库操作成功,恭喜你");%>  
  <%Rs.close();  
  stmt.close();  
  conn.close();  
  %>  
 
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载