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

上传人:自*** 文档编号:79782363 上传时间:2019-02-18 格式:DOC 页数:2 大小:60.30KB
返回 下载 相关 举报
加载jdbc数据库驱动三种常见方法_第1页
第1页 / 共2页
加载jdbc数据库驱动三种常见方法_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《加载jdbc数据库驱动三种常见方法》由会员分享,可在线阅读,更多相关《加载jdbc数据库驱动三种常见方法(2页珍藏版)》请在金锄头文库上搜索。

1、第一种Driverimport 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);Conn

2、ection conn = driver.connect(url, info);System.out.println(conn + conn); catch (SQLException e) e.printStackTrace();第二种:DriverManageimport java.sql.*;import java.util.Properties;public class HH public static void main(String args) try Driver driver = new com.mysql.jdbc.Driver();DriverManager.registe

3、rDriver(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 blo

4、cke.printStackTrace();第三种class.forname()import java.sql.*;import java.util.Properties;public class EE public static void main(String args) / TODO Auto-generated method stubtry Class.forName(com.mysql.jdbc.Driver);String url = jdbc:mysql:/localhost:3309/hh;Properties info = new Properties();info.setP

5、roperty(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 blocke.printStackTrace();catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号