JAVA JDBC驱动使用JDBC包 如何新建一个Connection

2024-12-21 03:33:40
推荐回答(2个)
回答1:

针对ORACLE数据库我给你一段代码吧
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:xhb" ;
conn = DriverManager.getConnection(url,"scott","tiger") ;

回答2:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://202.112.14.113:1433;DatabaseName=pubs","sa","sa");
Statement stmt=conn.createStatement();