JSP连接ACCESS数据库的简单代码
连接ACCESS数据库的简单JSP代码:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.sql.*" %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=" + application.getRealPath("jsp.mdb"); //与JSP文件同一目录下的ACCESS数据库文件名:jsp.mdb
Connection conn = DriverManager.getConnection(url,"",""); //连接ACCESS数据库(url,"用户名","密码"),为空即没有设置数据的登录密码。
Statement stmt=conn.createStatement();
String sql="select * from login"; //构造SQL语句
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
int id=rs.getInt("id"); //得到数据库里面的字段id的值。
String username=rs.getString("username"); //得到数据库里面的字段username的值。
String password=rs.getString("password");
}
//关闭与数据库的连接
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</center>
<html>
<head>
<title>连接数据库</title>
</head>
<body>
</body>
</html>
相关文档:
set adoCN =createobject("ADODB.CONNECTION")
set strCnn =createobject("ADODB.Recordset")
set rstSchema =createobject("ADODB.Recordset")
Dim I
dim n
str1 ......
探索软件工作室长期专业承接中小型商业软件或网站,最优惠的价格和高质量的服务期待您的惠顾!
本工作室承接 JSP ASP VB PB LotusNotes 等语言要求的应用系统开发业务
java jsp实战源程序代码:
......
在使用数据库的过程中,不可避免的需要使用到分页的功能,可是JDBC的规范对此却没有很好的解决。对于这个需求很多朋友都有自己的解决方案,比如使用Vector等集合类先保存取出的数据再分页。但这种方法的可用性很差,与JDBC本身的接口完全不同,对不同类型的字段的支持也不好。这里提供了一种与JDBC兼容性非常好的方案。
JD ......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace AddressList
{
public partial class FrmAccessUse : Form
{
public Fr ......