如何按照VS代码写java连接sqlserver的语句啊?

tatajciliang 2013-01-22 05:32:29
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 "数据库连接成功!"
End If

i = 0
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 '6 - 执行SQL语句,将结果保存在RECORDSET对象实例中


如上代码是连接数据库的,用VB写的,听朋友说数据库是SQLserver,所以打算用java连接sqlserver,但如上代码怎么转换成java连接sqlserver的代码啊?java连sqlserver的代码如下,怎么按照上面的方式对下面代码进行修改?

String strConn="jdbc:sqlserver://127.0.0.1:50037;DatabaseName=高校教务管理";
String strUser="ayuang";
String strPassword="Jame12$";
conn=DriverManager.getConnection(strConn,strUser,strPassword);//2
PreparedStatement pre=conn.prepareStatement("select * from HPD:HelpDesk");//3
System.out.println("链接数据库成功") ;
rs=pre.executeQuery();
while(rs.next())
{
String nianji=rs.getString(1);
System.out.println(""+nianji);
}
...全文
24 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
tatajciliang 2013-01-23
上面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 有人说按照这个代码判断是连接sqlserver的,如果数据库真的是sqlserver的话,那么连接sqlserver的语句该怎么写(就是说,下面这里怎么修改地址或数据库名之类的) String strConn="jdbc:sqlserver://127.0.0.1:50037;DatabaseName=高校教务管理"; String strUser="ayuang"; String strPassword="Jame12$"; conn=DriverManager.getConnection(strConn,strUser,strPassword);//2 PreparedStatement pre=conn.prepareStatement("select * from HPD:HelpDesk");//3
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
加入

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2013-01-22 05:32
社区公告
暂无公告