第20章 JDBC入门 使用JDBC连接数据库 使用JDBC进行数据操作
第20章 • JDBC入门 – 使用JDBC连接数据库 – 使用JDBC进行数据操作
简介JDBC 應用程式 JDBC MySQL Driver DB2 Driver Oracle Driver MySQL DB2 Oracle
简介JDBC
简介JDBC JDBC数据库驱动程序依实作方式可以分为 四个类型 Type 1: JDBC-ODBC Bridge Type 2: Native-API Bridge Type 3: JDBC-middleware Type 4: Pure Java Driver 應用程式 應用程式 應用程式 應用程式 JDBC-ODBC Bridge Native-API Bridge JDBC-middleware Pure Java Driver ODBC Driver Native Driver middleware 資料庫 資料庫 資料庫 資料庫
简介JDBC • JDBC数据库驱动程序依实作方式可以分为 四个类型 – Type 1:JDBC-ODBC Bridge – Type 2:Native-API Bridge – Type 3:JDBC-middleware – Type 4:Pure Java Driver
连接数据库 载人JDBC驱动程序 try i Class forName("com mysql jdbc Driver )i catch(ClassNotFoundException e) t System.out. println("找不到驱动程序类别");
连接数据库 • 载入JDBC驱动程序 try { Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e) { System.out.println("找不到驱动程序类别"); }
连接数据库 提供 JDBC URL 协定:子协定:数据源识别 jdbc:mysq1://主机名:端口/数据库名称?参数=值&参数=值 jdbc: mysql: //localhost: 3306/demo?user=root&password=123 jdbc: mysql: //localhost: 3306/demo?user=root&password=123& seUnicode=true& characterEncoding=Big 5
连接数据库 • 提供JDBC URL – 协定:子协定:数据源识别 jdbc:mysql://主机名:端口/数据库名称?参数=值&参数=值 jdbc:mysql://localhost:3306/demo?user=root&password=123 jdbc:mysql://localhost:3306/demo?user=root&password=123& useUnicode=true&characterEncoding=Big5