2013-01-02 75 views
0

而且我的代码是:com.microsoft.sqlserver.jdbc.SQLServerException:连接字符串包含一个格式错误的名称或值

 try{ 
     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
     Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost;jithin-pc:1433;databaseName=news;IntegratedSecurity=true"); 
     String qr="SELECT * FROM base"; 
     Statement st=con.createStatement(); 
     ResultSet rs=st.executeQuery(qr); 
     rs.next(); 
     System.out.println(rs.getString(1)); 
     out.println(rs.getString(1)); 

     } 
     catch(Exception e) 
     { 
      System.out.println(e); 
      out.println(e); 
     } 

我得到如下错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection string contains a badly formed name or value. 

我试图更改SQL设置防火墙等请任何建议

+0

不是此SQL Server Express的版本??? – mKorbel

+0

是的,它是..... – user1942089

回答

0

假设jithin pc是本地主机只是localhost或jithin pc应该是足够的。

jdbc:sqlserver://localhost;databaseName=news;IntegratedSecurity=true 
jdbc:sqlserver://jithin-pc;databaseName=news;IntegratedSecurity=true 

还要检查this

+0

但它不工作;但最后我找到了出路Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con = DriverManager.getConnection(“jdbc:odbc:jithin”,“username”,“password”); //现在转到控制面板中的管理工具并添加sql驱动程序.... !!感谢4的帖子 – user1942089

+0

他需要转义主机名而不是改变它 –