zoukankan      html  css  js  c++  java
  • eclipse 连接MySQL、SQL server数据库

    连接SQL server

    public class Test2 {
    
        public static void main(String[] args) {
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                System.out.println("加载数据库驱动成功");
                String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ipt";//声明数据库test的url
                String user="user";//数据库账号
                String pass="password";//数据库密码
                //建立数据库连接,获得连接对象conn
                Connection conn=DriverManager.getConnection(url,user,pass);
                System.out.println("数据库连接成功");
                Statement stmt=conn.createStatement();//创建一个Statement对象
                String sql="select * from cdr_raws";//生成一条sql语句
                ResultSet rs=stmt.executeQuery(sql);//执行查询,把查询结果赋值给结果集对象
                String callingPartyNumber;//声明2个变量分别为用户名,密码
                while(rs.next()){//遍历结果集
                    callingPartyNumber=rs.getString("callingPartyNumber");//
                    System.out.println(callingPartyNumber);
                }
                System.out.println("获得查询结果集");
                conn.close();
                System.out.println("关闭数据库连接对象");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }//加载数据库驱动
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    连接MySQL

    public class Test2 {
    
        public static void main(String[] args) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("加载数据库驱动成功");
                String url="jdbc:mysql://localhost:3306/test";//声明数据库test的url
                String user="root";//数据库账号
                String pass="pass";//数据库密码
                //建立数据库连接,获得连接对象conn
                Connection conn=DriverManager.getConnection(url,user,pass);
                System.out.println("数据库连接成功");
                Statement stmt=conn.createStatement();//创建一个Statement对象
                String sql="select * from account";//生成一条sql语句
                ResultSet rs=stmt.executeQuery(sql);//执行查询,把查询结果赋值给结果集对象
                String callingPartyNumber;//声明2个变量分别为用户名,密码
                while(rs.next()){//遍历结果集
                    callingPartyNumber=rs.getString("name");//
                    System.out.println(callingPartyNumber);
                }
                System.out.println("获得查询结果集");
                conn.close();
                System.out.println("关闭数据库连接对象");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }//加载数据库驱动
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    python接口自动化之发送post(四)
    python接口自动化之发送get(三)
    python接口自动化之fiddler使用(二)
    python读取yaml配置文件
    python接口自动化测试之http协议(一)
    python接口自动化测试之根据excel中的期望结果是否存在于请求返回的响应值中来判断用例是否执行成功
    python3读取、写入、追加写入excel文件
    python UI自动化之处理多窗口
    python UI自动化之js操作
    python UI自动化之切换iframe
  • 原文地址:https://www.cnblogs.com/RealWorld/p/8989226.html
Copyright © 2011-2022 走看看