当前位置:首页>开发>正文

idea加载jdbc驱动包 如何在eclipse下手动加载jdbc驱动

2023-04-11 23:08:46 互联网 未知 开发

idea加载jdbc驱动包 如何在eclipse下手动加载jdbc驱动

如何在eclipse下手动加载jdbc驱动

按照下面的做:

右键你的工程,然后点击build path -- add libraries -- user library - next - 点击user libraries-- new --- 输入名字 ,点OK 。 然后点击add external jars 添加你电脑里面的jdbc的jar包 点击ok,finish 就能往eclipse工程里面添加驱动了。

加载jdbc驱动有几种方法

第一种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() } } }

最新文章

随便看看