加载jdbc数据库驱动三种常见方法.docVIP

  • 5
  • 0
  • 约1.59千字
  • 约 2页
  • 2017-06-08 发布于重庆
  • 举报
加载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 ; 第三种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 ;

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档