zoukankan      html  css  js  c++  java
  • JAVA配置SQL2012

    1、下载JDBC驱动,安装;

    2、右击src文件构建配置路径添加sqljdbc4.jar添加外部Jar文件

    3、再测试 

    package test;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.*;

    public class test_sql {

    public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    // System.out.println("加载驱动成功");
    con = DriverManager
    .getConnection(
    "jdbc:sqlserver://192.168.1.2:1433;DatabaseName=dscfp2p",
    "sa", "ABcd123");
    // System.out.println("连接成功");
    String sql = "SELECT * FROM T_BankInfo";
    stmt = con.createStatement();
    rs = stmt.executeQuery(sql);
    while (rs.next()) {
    System.out.println(rs.getString(2) + " " + rs.getString(3)
    + " " + rs.getString(4) + " " + rs.getString(5));
    }

    } catch (Exception ex) {
    // System.out.println("连接失败");
    ex.printStackTrace();

    } finally {
    if (rs != null)
    try {
    rs.close();
    } catch (Exception e) {

    }
    if (stmt != null)
    try {
    stmt.close();
    } catch (Exception e) {

    }
    if (con != null)
    try {
    con.close();
    } catch (Exception e) {

    }
    }
    }
    }

  • 相关阅读:
    Mysql的select加锁分析
    浅析Kubernetes的工作原理
    HTTP/2部署使用
    Amazon新一代云端关系数据库Aurora
    为什么 kubernetes 天然适合微服务
    深入解读Service Mesh背后的技术细节
    微服务的接入层设计与动静资源隔离
    Prim算法和Kruskal算法介绍
    DAG及拓扑排序
    BFS和DFS
  • 原文地址:https://www.cnblogs.com/weijiafd/p/4543505.html
Copyright © 2011-2022 走看看