首页 > 数据库技术 > 详细

Java--Jdbc创建connection连接

时间:2021-08-22 23:20:24      阅读:20      评论:0      收藏:0      [点我收藏+]
/**
 * @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连接

原文:https://www.cnblogs.com/staynight/p/15173872.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!