首页 新闻 会员 周边

MyEclipse6.5连接不上sqlserver2008

0
悬赏园豆:50 [已解决问题] 解决于 2012-03-13 21:19
急求解在线等!!!我的MyEclipse连接不上sqlserver2008的不知道怎么回事 求解
每次程序进入BaseDao包中后就不出来了
就是这一句的
 
我的用户名和密码都是正确的(唯一一点的就是我的系统最近重装过的,但我的MyEclipse环境变量,JDK,tomcak也配置了,端口号也改了,服务也开了,但就是连接不上的!)
急求解在线等!!!
rocking_liuwu的主页 rocking_liuwu | 初学一级 | 园豆:112
提问于:2012-03-11 16:12
< >
分享
最佳答案
0

是tomcak的问题,程序本身没有任何错,晕~

rocking_liuwu | 初学一级 |园豆:112 | 2012-03-13 21:15
其他回答(4)
0

“每次程序进入BaseDao包中后就不出来了”。这句是什么意思?是抛异常了?还是什么?如果有异常把异常发出来啊。

憤怒的小鳥 | 园豆:206 (菜鸟二级) | 2012-03-11 19:38

控制台没有任何异常,运行时网页一直在访问状态不显示任何数据,像是死循环一样。。。。

支持(0) 反对(0) rocking_liuwu | 园豆:112 (初学一级) | 2012-03-13 21:06
0

急毛啊,淡定。先贴错误处理然后一切都好办。建议检查下驱动和计算机本身的问题

童同 | 园豆:258 (菜鸟二级) | 2012-03-11 21:59

为了解决这个问题,我的系统都重装了2次了。。。。

程序运行时控制台没有任何异常,运行时网页一直在访问状态不显示任何数据,像是死循环一样。。。。

支持(0) 反对(0) rocking_liuwu | 园豆:112 (初学一级) | 2012-03-13 21:09
0

贴出错误来

建议检查下数据库,看看端口是否配置成功,然后sa帐号有没有启用

az235 | 园豆:8483 (大侠五级) | 2012-03-12 09:10

非常感谢,下面是我的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;
 }

}

支持(0) 反对(0) rocking_liuwu | 园豆:112 (初学一级) | 2012-03-13 21:12
0
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;
}
}
 
换我这个试试,改改下看
收获园豆:50
秋风sao落叶 | 园豆:44 (初学一级) | 2012-03-12 11:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册