连接到SQL Server数据库时出错

时间:2015-05-21 09:04:46

标签: java php jsp

当我尝试使用以下代码连接到我的数据库时:

Select 
  a."System_Name",
  a."Comp_Mem_Pct",
  b."CPU_Usage",
  SUBSTR(a."Timestamp",2,2 )||'-'||SUBSTR(a."Timestamp",4,2)||'-'||SUBSTR(a."Timestamp",6,2) AS date_ 
from 
  "ITMUSER"."Unix_Memory" a, 
  "ITMUSER"."SMP_CPU" b 
where 
  a."System_Name"=b."System_Name" 
  and a."System_Name" in ('vil_amdox9:KUX','vil_ahmpumapp08_nsd:KUX')  

我收到以下异常:

  

错误:com.microsoft.sqlserver.jdbc.SQLServerDriver

我做错了什么?

2 个答案:

答案 0 :(得分:0)

试试这段代码

try
{
    String username = "sa";
    String password = "invent";
    String connectionUrl = "jdbc:sqlserver://192.168.0.78;instanceName=SQL2014;databaseName=GIDS";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = DriverManager.getConnection(connectionUrl,username,password);
    System.out.println("Database connection = "+con );
}
catch( Exception e )
{
    e.printStackTrace();
    System.out.println( "Error connecting to database.  Error: "+e.getMessage() );
}

答案 1 :(得分:0)

确保您拥有具有实现类(驱动程序jar)的jar,以便在类路径中连接o ms sql。