加载jdbc驱动有几种方法
4个回答
展开全部
方法一:Class.forName("驱动路径")
如:Class.forName("oracle.jdbc.driver.OracleDriver")
方法二:DriverManager.registerDriver(驱动实例)
如:DriverManager.registerDriver(new oracle.jdbc.OracleDriver())
如:Class.forName("oracle.jdbc.driver.OracleDriver")
方法二:DriverManager.registerDriver(驱动实例)
如:DriverManager.registerDriver(new oracle.jdbc.OracleDriver())
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一种Driver import java.sql.*;
import java.util.Properties;
public class GG { public static void main(String[] args) { try { Driver driver = new com.mysql.jdbc.Driver(); String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root"); info.setProperty("password", "root"); Connection conn = driver.connect(url, info); System.out.println("conn" + conn); } catch (SQLException e) { e.printStackTrace(); } } }
第二种:DriverManage import java.sql.*;
import java.util.Properties;
public class HH { public static void main(String[] args) { try { Driver driver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(driver); String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root"); info.setProperty("password", "root"); Connection conn = DriverManager.getConnection(url, info); System.out.println("conn" + conn); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);
}
第三种class.forname()
import java.sql.*;
import java.util.Properties; public class EE {
public static void main(String[] args) { // TODO Auto-generated method stub try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root");
info.setProperty("password", "root"); Connection conn;
conn = DriverManager.getConnection(url, info); System.out.println("conn" + conn); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace(); } } }
import java.util.Properties;
public class GG { public static void main(String[] args) { try { Driver driver = new com.mysql.jdbc.Driver(); String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root"); info.setProperty("password", "root"); Connection conn = driver.connect(url, info); System.out.println("conn" + conn); } catch (SQLException e) { e.printStackTrace(); } } }
第二种:DriverManage import java.sql.*;
import java.util.Properties;
public class HH { public static void main(String[] args) { try { Driver driver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(driver); String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root"); info.setProperty("password", "root"); Connection conn = DriverManager.getConnection(url, info); System.out.println("conn" + conn); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);
}
第三种class.forname()
import java.sql.*;
import java.util.Properties; public class EE {
public static void main(String[] args) { // TODO Auto-generated method stub try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3309/hh"; Properties info = new Properties(); info.setProperty("user", "root");
info.setProperty("password", "root"); Connection conn;
conn = DriverManager.getConnection(url, info); System.out.println("conn" + conn); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace(); } } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
type 1:jdbc-odbc桥
type 2:本地api驱动
type 3:网络协议驱动
type 4:本地协议驱动
type 2:本地api驱动
type 3:网络协议驱动
type 4:本地协议驱动
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询