无法将JDBC连接到SQL服务器?

时间:2013-01-03 08:17:25

标签: java sql-server database jdbc

我正在尝试连接到我在SQL Server 2008中创建的本地数据库,但我已经尝试了所有但是出现了相同的错误,我在数据库资源管理器中被连接但需要从我的应用程序连接到数据库以用于注册页面并登录。这是我的错误:

    #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (classFileParser.cpp:3470), pid=5644, tid=5492
#  Error: ShouldNotReachHere()
#
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0-b17 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\christiej\workspace\MainActivity\hs_err_pid5644.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

这是我的代码:

    public class Example
{
   public static void main (String[] args) throws SQLException, ClassNotFoundException{

   Class.forName("com.sqlserver.jdbc.Driver"); // Setup the connection with the DB

   Connection connect = DriverManager.getConnection("jdbc:sqlserver://192.168.0.13:1433/Risk_ProfilingV2","sa","Dsolve01#");  

 // Statements allow to issue SQL queries to the database
    java.sql.Statement statement = connect.createStatement();

 // Result set get the result of the SQL query
 ResultSet resultSet = null;
try {
    resultSet = statement.executeQuery("select * from User_Table");
} catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

     while (resultSet.next()) {  //retrieve data
         String data = resultSet.getString("User_Name");

      }
}

}

1 个答案:

答案 0 :(得分:0)