请问各位大仙,jsp案例为何不能显示数据? 我运行一个JSP案例(tomcat已配置好,sql 2000数据库也已设好),页面能够打开,但无数据显示.请问各位如何解决. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1433端口已打开package com.bwm.db;import java.sql.*;/** *class explain:Database connection *set up name: crazyadept *set up time: 11/22/2004 */public class Conn { private static Connection con; private Statement stmt; private ResultSet rs; private static final String drivername = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; private static final String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=db_Job;user=sa;password=sa;"; /** *method explain: Get Connection DataBase *modify time: 12/20/2004 */ public static synchronized Connection getCon() throws Exception { // try { Class.forName(drivername); con = DriverManager.getConnection(url); return con; //} catch (SQLException e) { // System.err.println(e.getMessage()); // throw e; // } } /** *output parameter: in order select in SQL *modify time: 12/20/2004 */ public Statement getStmtread() { try { con = getCon(); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); return stmt; } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } return null; } /** *output parameter: Data *input parameter: SQL select sentence *modify time: 11/29/2004 */ public ResultSet getRs(String sql) { try { stmt = getStmtread(); rs = stmt.executeQuery(sql); return rs; } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } return null; } /** *output parameter: not in order select in str SQL *modify time: 11/29/2004 */ public Statement getStmt() { try { con = getCon(); stmt = con.createStatement(); return stmt; } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } return null; } /** *method explain: Close DataBase Connection *modify time: 11/29/2004 */ public synchronized void close() { try { if (rs != null) { rs.close(); rs = null; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } try { if (stmt != null) { stmt.close(); stmt = null; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } try { if (con != null) { con.close(); con = null; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } }} 1,写个输出语句或者debug一下,看看你是否真的从db里得到数据了,如果没有的话,调试你的sql语句,直至得到结果为止。2,是否正确的把从db中得到的结果传送到了页面,比如你是把数据放到request或者session里,那么你在页面就要用同样的名字把它取出来 sqlserver 要打一个sp4 的补丁! public static synchronized Connection getCon() throws Exception { // try { Class.forName(drivername); con = DriverManager.getConnection(url); System.out.println(con);//加这一句看看与数据的连接好了没有 return con; //} catch (SQLException e) { // System.err.println(e.getMessage()); // throw e; // } }你在其它地方是怎么用这个类的对像啊...代码放出来 ResultSet rs = new Conn().getRs("select * from tableName");if(rs.next()){ System.out.println("数据库里有记录!");} 兄弟,debug一下不就知道了,看看你的程序报异常了没?执行到哪儿了,才出的异常,贴出来看看就知道了 新手零起步,求个spring3.0的配置教程 ftp上传文件名为中文问题,在线等! jsp +crystal reports 老是出错 这段字符串哪里错了 新建的SQLServer 数据库无法链接上 自动显示问题?? 求一个javascript的动态菜单 一个简单html的问题 在线等待 这里有会chef 部署的人么 ArrayList的问题 鸡鸡鸡鸡鸡鸡鸡鸡鸡 从数据库里面获取list,在页面上怎么样让html:multibox是选中? servlet错误,请帮忙
package com.bwm.db;import java.sql.*;/**
*class explain:Database connection
*set up name: crazyadept
*set up time: 11/22/2004
*/
public class Conn {
private static Connection con;
private Statement stmt;
private ResultSet rs;
private static final String drivername =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=db_Job;user=sa;password=sa;"; /**
*method explain: Get Connection DataBase
*modify time: 12/20/2004
*/
public static synchronized Connection getCon() throws Exception {
// try {
Class.forName(drivername);
con = DriverManager.getConnection(url);
return con;
//} catch (SQLException e) {
// System.err.println(e.getMessage());
// throw e;
// }
} /**
*output parameter: in order select in SQL
*modify time: 12/20/2004
*/
public Statement getStmtread() {
try {
con = getCon();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
return stmt;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
*output parameter: Data
*input parameter: SQL select sentence
*modify time: 11/29/2004
*/
public ResultSet getRs(String sql) {
try {
stmt = getStmtread();
rs = stmt.executeQuery(sql);
return rs;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
*output parameter: not in order select in str SQL
*modify time: 11/29/2004
*/
public Statement getStmt() {
try {
con = getCon();
stmt = con.createStatement();
return stmt;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
*method explain: Close DataBase Connection
*modify time: 11/29/2004
*/
public synchronized void close() {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
try {
if (con != null) {
con.close();
con = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
// try {
Class.forName(drivername);
con = DriverManager.getConnection(url);
System.out.println(con);//加这一句看看与数据的连接好了没有
return con;
//} catch (SQLException e) {
// System.err.println(e.getMessage());
// throw e;
// }
}
你在其它地方是怎么用这个类的对像啊...代码放出来
{
System.out.println("数据库里有记录!");
}