zoukankan      html  css  js  c++  java
  • oracle ,mysql,postgres jdbc配置文件

    #db mysql
    #jdbc.driver=com.mysql.jdbc.Driver
    #jdbc.url=jdbc:mysql://localhost:3306/mysql?&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull
    #jdbc.username=root
    #jdbc.password=
    #在xml配置文件中,url中的&符号需要转义成&。比如在tomcat的server.xml中配置数据库连接池时,mysql jdbc url样例如下
    #jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf-8
    
    #db oracle
    #jdbc.driver=oracle.jdbc.driver.OracleDriver
    #jdbc.url="jdbc:oracle:thin:@192.168.8.1:1521:orcl
    #jdbc.username=root
    #jdbc.password=
    #http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
    
    #db postgress
    jdbc.driver=org.postgresql.Driver
    jdbc.url=jdbc:postgresql://localhost/soft
    jdbc.username=postgres
    jdbc.password=postgres
    #https://jdbc.postgresql.org/download.html
    package com.sdzw.wgn;
    
    import java.sql.DriverManager;  
    import java.sql.ResultSet;  
    import java.sql.SQLException;  
    import java.sql.Connection;  
    import java.sql.Statement;  
    
    public class JDBC_Test {
        
        public void test() {
            Connection conn =  null;
            // MySQL的JDBC URL编写方式:jdbc:mysql://主机名称:连接端口/数据库的名称?参数=值  
            // 避免中文乱码要指定useUnicode和characterEncoding  
            String url = "jdbc:mysql://localhost:3306/test?"  
                    + "user=root&password=123456&useUnicode=true&characterEncoding=UTF8";  
            try {  
      
                // 之所以要使用下面这条语句,是因为要使用MySQL的驱动,所以我们要把它驱动起来,  
                // 可以通过Class.forName把它加载进去,也可以通过初始化来驱动起来,下面三种形式都可以  
                Class.forName("com.mysql.jdbc.Driver");// 动态加载mysql驱动  
                // or:  
                // com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();  
                // or:  
                // new com.mysql.jdbc.Driver();  
                System.out.println("成功加载MySQL驱动程序");  
                // 一个Connection代表一个数据库连接  
                conn = DriverManager.getConnection(url);  
                // Statement里面带有很多方法,比如executeUpdate可以实现插入,更新和删除等  
                Statement stmt = conn.createStatement();  
                String sql = "create table student(NO char(20),name varchar(20),primary key(NO))";  
                int result = stmt.executeUpdate(sql);// executeUpdate语句会返回一个受影响的行数,如果返回-1就没有成功  
      
                if (result != -1) {  
                    System.out.println("创建数据表成功");  
                    sql = "insert into student(NO,name) values('2016001','刘大')";  
                    result = stmt.executeUpdate(sql);  
                    sql = "insert into student(NO,name) values('2016002','陈二')";  
                    result = stmt.executeUpdate(sql);  
                    sql = "select * from student";  
                    ResultSet rs = stmt.executeQuery(sql);// executeQuery会返回结果的集合,否则返回空值  
                    System.out.println("学号	姓名");  
                    while (rs.next()) {  
                        System.out.println(rs.getString(1)+ "	" + rs.getString(2));// 入如果返回的是int类型可以用getInt()  
                    }  
                }  
            } catch(SQLException e) {  
                System.out.println("MySQL操作错误");  
                e.printStackTrace();  
            } catch (Exception e) {  
                e.printStackTrace();  
            } finally {  
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }  
            }  
        }
    
        public static void main(String[] args) {
    
        }
    
    }
        public void getJDBCPros(String path) throws IOException {
            Properties properties = new Properties();
            InputStream in = new BufferedInputStream(new FileInputStream(path));
            properties.load(in);
            
            String driver = properties.getProperty("jdbc.driver");
            String url = properties.getProperty("jdbc.url");
            String username = properties.getProperty("jdbc.username");
            String password = properties.getProperty("jdbc.password");
        }
  • 相关阅读:
    将Nginx添加到windows服务中
    springboot使用redis管理session
    GIT常用命令
    阻止360、谷歌浏览器表单自动填充
    谈谈对Spring IOC的理解
    同一个Nginx服务器同一端口配置多个代理服务
    LeetCode 653. Two Sum IV
    109. Convert Sorted List to Binary Search Tree(根据有序链表构造平衡的二叉查找树)
    108. Convert Sorted Array to Binary Search Tree(从有序数组中构造平衡的BST)
    LeetCode 236. Lowest Common Ancestor of a Binary Tree(二叉树求两点LCA)
  • 原文地址:https://www.cnblogs.com/wangguoning/p/7091720.html
Copyright © 2011-2022 走看看