package utilDb;import java.sql.*;
import java.io.*;public class DBConnection {
public static void getMyConnection()
{
Connection conn=null;
Statement statement=null;
String connDB="jdbc:odbc:bookstore";
String userName="sa";
String userPassword="";
String sql="select * from t_book";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(connDB,userName,userPassword);
statement =conn.createStatement();
ResultSet rs=statement.executeQuery(sql);
if(conn!=null)
{
rs.close();
statement.close();
conn.close();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
getMyConnection();
}
}<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%>
<%@ page import="utilDb.DBConnection" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<table width="300" border="3">
<tr>
<th scope="col">bookid</th>
</tr>
<%
ResultSet rs=null;
DBConnection.getMyConnection();
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getString("bookid")+"</td>");
out.println("</tr>");
}
rs.close();
%>
</table>
</body>
</html>
解决方案 »
- 如果在struts处理方法中获得当前项目路径?求解,试了好多都不行呢
- 十六进制字符串转换为Integer
- Struts2 result type="chain" 问题
- jquery easyui 使用后台的json
- 可不可以实现这样的功能????
- jsf+tiles框架的配置
- 刚学struts,就对userform,晕,请教各位,多谢
- 谁能提供点JBOSS+RESIN+LINUX整合,配置,开发的资料
- 还是jdbc连sql200问题,求教
- jboss下用sessionBean的container控制事务不起作用?详见>>
- jsp接收action传来的list,老是提示没发现get方法
- struts2怪问题,在Firefox下正常,在IE下就不正常了
DBConnection.getMyConnection();
while(rs.next())rs=null了,还怎么next;