JDBC的JDBC示例
我已经下载了JDK 6,我也有sqljdb4.jar,我有
database.properties文件,其中包含以下数据
database.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver database.url=jdbc:sqlserver://.;databaseName=UserInfo;integratedSecurity=true; database.username=sa database.password=admin B.N:我正在我的机器上安装服务器,服务器名称=.,我也在使用Windows Authontication 我现在的问题是当我尝试创建连接时出现以下错误
我不知道这里的确切问题是什么 如果任何人可以帮助我将不胜感激 提前致谢 解决方法
这是由许多概率引起的
1- IP是worong 2-端口错误 3-防火墙防止机器外出并连接到另一个IP 4- SQL服务器关闭. 试着用 public class JdbcSQLServerDriverUrlExample { public static void main(String[] args) { Connection connection = null; try { // the sql server driver string Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // the sql server url String url = "jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=DATABASE"; // get the sql server database connection connection = DriverManager.getConnection(url,"THE_USER","THE_PASSWORD"); // now do whatever you want to do with the connection // ... } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); } catch (SQLException e) { e.printStackTrace(); System.exit(2); } } } 我需要解释的是,有一种非常好的技术称为“持久性”,它比JDBC更好,并且非常出色且易于使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |