如下代码连接数据库的,怎么判断是哪个数据库,怎么用java连接数据库?
请问我们公司用VB写如下代码连接数据库
Set objConnection = CreateObject("ADODB.CONNECTION")
strConnectionString = "DSN=AR System ODBC Data Source;ARServer=globalar.jci.com;UID=ayuang;PWD=Jame12$;ARAuthentication=;ARUseUnderscores=1;SERVER=NotTheServer"
objConnection.Open strConnectionString
If (objConnection.State = 1) Then
MsgBox "数据库连接成功!"
str_Array_QueryResult = Array() '重新初始化数组为一个空数组
Set rs = CreateObject("ADODB.RECORDSET") '4 - 建立RECORDSET对象实例
Set objCommand = CreateObject("ADODB.COMMAND") '5 - 建立COMMAND对象实例
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT "&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Case ID+"&chr(34)&" from "&chr(34)&"HPD:HelpDesk"&chr(34)&" "&chr(34)&"HPD:HelpDesk"&chr(34)&" WHERE ("&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Assigned To Group+"&chr(34)&" Like "&chr(39)&"%apac.gen.as%"&chr(39)&") OR ("&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Entry Group"&chr(34)&" Like "&chr(39)&"%apac.gen.as%"&chr(39)&") ORDER BY "&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Case ID+"&chr(34)&""
rs.CursorLocation = 3
rs.Open objCommand
如上代码能知道是哪个数据库吗?我想用java连接如上数据库该怎么写语句?
[解决办法]
sqlserver
[解决办法]
这个程序是用ODBC连的,建议去控制面板-管理数据-数据源 看看连接属性,直接连数据库,没必要用ODBC桥连接
[解决办法]
String user="sa";
String pwd="1234";
String driver_class="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://localhost:1433;databaseName=car";
Class.forName(driver_class);
//获得数据库连接
Connection conn=DriverManager.getConnection(url,user,pwd);
//创建语句对象
Statement stmt=conn.createStatement();
//发出查询命令
ResultSet rs=stmt.executeQuery("select id,name from user");
[解决办法]
如果能找到连接的是什么数据库,那么你就可以使用楼上提供的方式去连接了。
[解决办法]