1.与access <%@page contentType = "text/html;charset=GB2312" import = "java.sql
.*"%>
<%@page import = "java.util.*,java.text.*"%>
<html>
<title>取出并显示表中的信息</title>
<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:webdata");
Statement smt = con.createStatement();
String sql;
sql = "select bh,shrxx,shrdh,shrdz,hwjs,bzxs,yf,bjd from hy";
ResultSet rs = smt.executeQuery(sql);
out.println("取出表中的的所有信息");
%>
请点击这里</font><a href="javascript:history.back(1)"><b><font color="#FF0000"
>返回</font></b></a><hr>
<%
out.println("<table border = '1'>");
out.println("<tr bgcolor = 'yellow'><th>货单号</th><th>收货人姓名</th><th>收货
人电话</th><th>收货人住址</th><th>货件数量</th><th>包装形式</th><th>运费</th><
th>报价单</th></tr>");
while(rs.next())
out.println("<tr><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</
td><td>" + rs.getString(3) + "</td><td>" + rs.getString(4) + "</td><td>" + rs.
getString(5) + "</td><td>" + rs.getString(6) + "</td><td>" + rs.getString(7) +
"</td><td>" + rs.getString(8) + "</td></tr>" );
con.close();
%>
<html>
<body>
</table>
</body>
</html>
2.与mysql
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://192.168.0.1:3306/test?user=root&password=123";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.
CONCUR_UPDATABLE);
String sql="select * from huahe_article";
ResultSet rs=stmt.executeQuery(sql); %>
<table><tr><td>您的第一个字段内容为:</td>
<td>您的第二个字段内容为:</td></tr>
<%
while(rs.next()) {%>
<tr><td>
<%=rs.getString(1)%> </td><td>
<%=rs.getString(2)%> </td></tr>
<%}%>
</table>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
3.与mssql
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%!
public static String getGBString(String src) {
try {
return new String(src.getBytes("ISO-8859-1"), "gb2312");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
}
%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://192.168.0.1:1433;DatabaseName=test";
//test你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.
CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=getGBString(rs.getString(1))%> <br>
您的第二个字段内容为:<%=getGBString(rs.getString(2))%> <br>
<%}%>
<%out.print("数据库操作成功,恭喜你");%> <br>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
如上的连接方法只能作为学习之用!和简单个人主页