我最近尝试使用JDBC驱动程序配置MS SQLServer,我已经安装了SQL SERVER EXPRESS版2016和JDBC DRIVER 4(sqljdbc 4.0)。修改并运行net中的示例代码以用于我自己的测试目的我得到了这个错误
com.microsoft.sqlserver.jdbc.SQLServerException: The server sqlexpress is not configured to listen with TCP/IP.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3603)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcTest.main(JdbcTest.java:24)
I have taken these step for the solution
1.I have disabled firewall
2.Enable TCP/IP for SQLSERVER(SQLEXPRESS) from configuration manager
3.I have given port number 1434
4.Enabled SQL Browser Services
但代码没有编译。这是我的代码:
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcTest {
public static void main (String[]args)
{
Connection con=null;
try{
String dbURL = "jdbc:sqlserver://localhost\\SQLEXPRESS;user=codemen;password=";
//String user="codemen";
//String password="cd";
//DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
con=DriverManager.getConnection(dbURL);
if(con!=null)
{
DatabaseMetaData dm=(DatabaseMetaData)con.getMetaData();
System.out.println("Driver name: "+" " +dm.getDriverName());
System.out.println("Driver version :" +" "+ dm.getDriverVersion());
System.out.println("Product name: " + dm.getDatabaseProductName());
System.out.println("Product version: " + dm.getDatabaseProductVersion());
}
}
catch(SQLException ex)
{
ex.printStackTrace();
}
finally
{
try{
if (con !=null && !con.isClosed())
{
con.close();
}
}
catch(SQLException sq)
{
sq.printStackTrace();
}
}
}
}
如果我得到克服这些问题的指导方针,那将会很有帮助。提前致谢