Java--Jdbc创建connection连接

/**
 * @author staynight
 * jdbc learning test class
 */
public class JdbcLearning {
    @Test
    public void jdbcConnection(){
        Properties properties = new Properties();
        try {
            properties.load(JdbcLearning.class.getClassLoader().getSystemResourceAsStream("jdbc.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        String className=properties.getProperty("className");
        String url=properties.getProperty("url");
        String username=properties.getProperty("username");
        String password=properties.getProperty("password");
        try {
            Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            Connection connection = DriverManager.getConnection(url, username, password);
            System.out.println(connection);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

}

Java--Jdbc创建connection连接

上一篇:Hibernate简易BaseDao演示单例


下一篇:linux开关机命令