大佬教程收集整理的这篇文章主要介绍了SQLServer连接语句,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class @H_618_11@sqlServerTest {
@H_618_11@ //驱动类
@H_618_11@ static@H_618_11@String driverClass@H_618_11@=
@H_618_11@ "com.microsoft.jdbc.sqlserver.sqlServerDriver"@H_618_11@;
@H_618_11@ //连接字符串
@H_618_11@ static@H_618_11@String url@H_618_11@=
@H_618_11@ "jdbc:microsoft:sqlserver://127.0.0.1:1433;dataBasename=Test"@H_618_11@;
@H_618_11@ //密码
@H_618_11@ static@H_618_11@String password@H_618_11@= "Peter"@H_618_11@;
@H_618_11@ // 用户名
@H_618_11@ static@H_618_11@String username@H_618_11@= "Peter"@H_618_11@;
@H_618_11@ //待执行的 sql 语句
@H_618_11@ static@H_618_11@String sql@H_618_11@= "SELECT * FROM test"@H_618_11@;
@H_618_11@ publicstatic void@H_618_11@main(String[] args) {
@H_618_11@ Connection conn = null @H_618_11@;
@H_618_11@ PreparedStatement pstmt =null @H_618_11@;
@H_618_11@ ResultSet rs = null@H_618_11@;
@H_618_11@ Class.forName(driverClass @H_618_11@);
@H_618_11@ conn = DriveRMANager.getConnection(url @H_618_11@,username @H_618_11@,password @H_618_11@);
@H_618_11@ pstmt = conn.prepareStatement(sql @H_618_11@);
@H_618_11@ rs = pstmt.executeQuery();
@H_618_11@ while@H_618_11@(rs.next()) {
@H_618_11@ System. out@H_618_11@.println( "OK."@H_618_11@);
@H_618_11@ }
@H_618_11@ System. out@H_618_11@.println( "OK too."@H_618_11@);
@H_618_11@ } catch@H_618_11@(ClassnotFoundException E) {
@H_618_11@ System. out@H_618_11@.println( "驱动类没有找到 ." @H_618_11@);
@H_618_11@ e.printstacktrace();
@H_618_11@ } catch@H_618_11@(sqlException E) {
@H_618_11@ e.printstacktrace();
@H_618_11@ } finally@H_618_11@{
@H_618_11@ if@H_618_11@(rs != null@H_618_11@) //结果集没有关闭时关闭结果集
@H_618_11@ } catch@H_618_11@(sqlException E) {
@H_618_11@ e.printstacktrace();
@H_618_11@ }
@H_618_11@ if@H_618_11@(pstmt != null@H_618_11@) //发送对象没有关闭时关闭发送对象
@H_618_11@ } catch@H_618_11@(sqlException E) {
@H_618_11@ e.printstacktrace();
@H_618_11@ }
@H_618_11@ if@H_618_11@(conn != null@H_618_11@) //连接没有关闭时关闭连接
@H_618_11@ } catch@H_618_11@(sqlException E) {
@H_618_11@ e.printstacktrace();
@H_618_11@ }
@H_618_11@ }
@H_618_11@ }
@H_618_11@}
@H_618_11@that well does capture Exception program .
原地址:http://www.blogjava.net/lPeter/archive/2006/12/22/89501.html
以上是大佬教程为你收集整理的SQLServer连接语句全部内容,希望文章能够帮你解决SQLServer连接语句所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。