加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver 连接

发布时间:2020-12-12 12:43:03 所属栏目:MsSql教程 来源:网络整理
导读:package demosql;import java.sql.*;public class test {?static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";?static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=test";?static final String USER = "s

package demosql;import java.sql.*;public class test {?static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";?static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=test";?static final String USER = "su";?static final String PWD = "zhang";?static Statement sm = null;?static Connection con = null;??public static void main(String args[]){????try {??????Class.forName(DRIVER);??????con = DriverManager.getConnection(URL,USER,PWD);???Statement sm = con.createStatement();???int i = sm.executeUpdate("insert into 部门? values(4,'yyy')");???if(i == 1)????System.out.println("Success");???else????System.out.println("Fail");??????} catch (ClassNotFoundException e) {???????// TODO Auto-generated catch block??????e.printStackTrace();????System.out.println("not found");} ??catch (SQLException e) {??????// TODO Auto-generated catch block?????e.printStackTrace();??}???finally{???if(sm != null)????try {?????sm.close();????} catch (SQLException e) {?????// TODO Auto-generated catch block?????e.printStackTrace();????}???if(con != null)????try {?????con.close();????} catch (SQLException e) {?????// TODO Auto-generated catch block?????e.printStackTrace();????}??}?//?return con;??}?}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读