是tomcak的问题,程序本身没有任何错,晕~
“每次程序进入BaseDao包中后就不出来了”。这句是什么意思?是抛异常了?还是什么?如果有异常把异常发出来啊。
控制台没有任何异常,运行时网页一直在访问状态不显示任何数据,像是死循环一样。。。。
急毛啊,淡定。先贴错误处理然后一切都好办。建议检查下驱动和计算机本身的问题
为了解决这个问题,我的系统都重装了2次了。。。。
程序运行时控制台没有任何异常,运行时网页一直在访问状态不显示任何数据,像是死循环一样。。。。
贴出错误来
建议检查下数据库,看看端口是否配置成功,然后sa帐号有没有启用
非常感谢,下面是我的BaseDao,貌似没有错的,你看看
package com.scce.dao;
import java.io.Serializable;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
public class BaseDAO implements Serializable {
private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String URL = "jdbc:sqlserver://localhost:1433;databasename=GameCard_DB";
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, "sa", "scce");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
/**************************************************** 执行SQL语句 *********************************************************/
// 运行有结果集,无参数的sql语句
public static Result runSelectSql(String sql) {
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
Result result = null;
try {
con = getConnection();
ps = con.prepareStatement(sql);
res = ps.executeQuery();
result = ResultSupport.toResult(res);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
res.close();
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
// 运行有结果集,有参数的sql语句
public static Result runSelectSql(String sql, Object[] params) {
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
Result result = null;
try {
con = getConnection();
ps = con.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
ps.setObject(i + 1, params[i]);
}
res = ps.executeQuery();
result = ResultSupport.toResult(res);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
res.close();
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
// 运行无结果集,无参数的sql语句
public static boolean runUpdateSql(String sql) {
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement(sql);
ps.executeUpdate();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 运行无结果集,有参数的sql语句
public static boolean runUpdateSql(String sql, Object[] params) {
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
ps.setObject(i + 1, params[i]);
}
ps.executeUpdate();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**************************************************** 执行存储过程语句 *********************************************************/
// 无结果集,无参数的存储过程
public static boolean runUpdateByProc(String procName) {
Connection con = null;
CallableStatement cs = null;
try {
con = getConnection();
String proc = String.format("{call %s()}", procName);
cs = con.prepareCall(proc);
return cs.executeUpdate() > 0;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
cs.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
// 无结果集,有参数的存储过程
public static boolean runProcUpdate(String procName, Object[] params) {
Connection con = null;
CallableStatement cs = null;
try {
con = getConnection();
String proc = "{call " + procName + "(";
for (int i = 0; i < params.length; i++) {
proc += "?,";
}
proc = proc.substring(0, proc.length() - 1) + ")}";
cs = con.prepareCall(proc);
for (int i = 0; i < params.length; i++) {
// 说明是输入参数
if (params[i] != null) {
cs.setObject(i + 1, params[i]);
}
// 否则输出参数,就要注册
else {
// 第一个为位置,第二个为类型
cs.registerOutParameter(i + 1, java.sql.Types.VARCHAR);
}
}
cs.executeUpdate();// 只是执行了存储过程,但是还没有把执行赋给输出参数
for (int i = 0; i < params.length; i++) {
if (params[i] == null) { // 说明是输出参数
params[i] = cs.getObject(i + 1);
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
cs.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 有结果集,无参数的存储过程
public static Result runSelectByProc(String procName) {
Connection con = null;
ResultSet res = null;
Result result = null;
CallableStatement cs = null;
try {
con = getConnection();
String proc = String.format("{call %s}", procName);
cs = con.prepareCall(proc);
res = cs.executeQuery();
result = ResultSupport.toResult(res);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
res.close();
cs.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
// 有结果集,有参数的存储过程
public static Result runSelectByProc(String procName, Object[] params) {
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
Result result = null;
CallableStatement cs = null;
try {
con = getConnection();
String proc = "{call " + procName + "(";
for (int i = 0; i < params.length; i++) {
proc += "?,";
}
proc = proc.substring(0, proc.length() - 1) + ")}";
cs = con.prepareCall(proc);
for (int i = 0; i < params.length; i++) {
if (params[i] != null)
{
cs.setObject(i + 1, params[i]);
} else
{
cs.registerOutParameter(i + 1, java.sql.Types.VARCHAR);
}
}
res = cs.executeQuery();
result = ResultSupport.toResult(res);
for (int i = 0; i < params.length; i++) {
if (params[i] == null)
{
params[i] = cs.getObject(i + 1);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
cs.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
}
package com.dao;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
public class BaseDao {
public static final String DRIVER ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static final String URL = "jdbc:sqlserver://localhost:1433;database=Adressbook";
public static final String USER="sa";
public static final String PWD="";
//创建链接
public Connection getConnection()
{
Connection conn =null;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL,USER,PWD);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
//执行添删改
public int executeUpdate(String sql,Object...param)
{
Connection conn =null;
PreparedStatement pst = null;
int row = 0;
conn = getConnection();
try {
pst = conn.prepareStatement(sql);
if (param!=null) {
for (int i = 0; i < param.length; i++) {
pst.setObject(i+1,param[i]);
}
}
row=pst.executeUpdate();
pst.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return row;
}
public Result executeQuery(String sql,Object...param)
{
Connection conn = null;
Result rs =null;
ResultSet rst = null;
PreparedStatement pst = null;
conn = getConnection();
try {
pst = conn.prepareStatement(sql);
if (param!=null) {
for (int i = 0; i < param.length; i++) {
pst.setObject(i+1, param[i]);
}
}
rst=pst.executeQuery();
rs = ResultSupport.toResult(rst);
rst.close();
pst.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
换我这个试试,改改下看