dygf19877
2010-11-29 16:53
采纳率: 0%
浏览 360
已采纳

jtds连接数据库爆出sqlexception

编程工具是myecplise8.6,我在myecplise里已经成功配置好了数据库,但是程序里面异常,请大家帮忙解决以下
[code="java"]import java.sql.*;

public class SqlTest {

private String driverClass = "net.sourceforge.jtds.jdbc.Driver";

private String url ="jdbc:jtds:sqlserver:/localhost:1433/demo";

private String user = "sa";

private String password = "";

private Connection connection;

public Connection openConnection() throws SQLException {
    try {

        Class.forName(driverClass).newInstance();
        System.out.println("Successful");
        connection = DriverManager.getConnection(url, user, password); 

        return connection;
    } catch (Exception e) {
        throw new SQLException(e.getMessage());
    }
}

public void closeConnection() {
    try {        
        if (connection != null)
            connection.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public static void main(String[] args) throws SQLException{
    SqlTest st=new SqlTest();
    Connection con=st.openConnection();
    Statement stmt = con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from STCKSZ");
    rs.next();
    System.out.println(rs.getInt(1));

}

} [/code]

异常信息:
Exception in thread "main" java.sql.SQLException: net.sourceforge.jtds.jdbc.Driver
at test.SqlTest.openConnection(SqlTest.java:25)
at test.SqlTest.main(SqlTest.java:39)
麻烦大家拉

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题