首页 > 代码库 > java 数据库连接

java 数据库连接

JDBC基本用法

jdbc.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test
jdbc.username=root
jdbc.password=root
public static Connection getConnection() throws IOException, ClassNotFoundException, SQLException {
    Properties props = new Properties();
    props.load(new FileInputStream("jdbc.properties"));
    Class.forName(props.getProperty("jdbc.driverClass"));
    String url = props.getProperty("jdbc.url");
    String username = props.getProperty("jdbc.username");
    String password = props.getProperty("jdbc.password");
    return DriverManager.getConnection(url, username, password);
}

DBCP

Spring

JPA

Hibernate

java 数据库连接