谁能帮我分析一下这串代码啊 这是不是编写一个访问数据库的Servlet啊

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:17:55
jsp连接access数据库
<%@page import="java.sql.*"
import ="java.util.*"
import ="java.io.*"
import="java.text.*"
contenttype="text/html; charset=gb2312"
buffer="20kb"
%><%! int all,i,m_count;
string odbcquery;
connection odbcconn;
statement odbcstmt;
resultset odbcrs;
string username,title,content,work,email,url,time,date;
string datetime;
%>
<%
try{
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
}catch (classnotfoundexception e)
{ out.print ("驱动程序不存在");
}
try{
odbcconn = drivermanager.getconnection("jdbc:odbc:db1");
odbcstmt = odbcconn.createstatement();
odbcquery="select * from book where datetime>2001-4-26 order by datetime desc";
odbcrs=odbcstmt.executequery(odbcquery);
int i=0;
while (i<130) odbcrs.next();

连接数据库:Class.forName("com.mysql.jdbc.Driver").newInstance();
odbcconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbase","root","mysql");
odbcstmt=odbcconn.createStatement();
odbcrs=odbcstmt.executeQuery(odbcquery);
其中3306/后面得dbase是数据库名,root 是用户名,mysql是你安装MYSQL 数据库时设的密码 你把数据库名和密码改成你自己设置的名字和密码 用户名就不用动了,这段代码就是用来连接数据库的。