您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > Java与数据库的连结
Java---JDBC6903005xiaomingxy@msn.com2JavaJava——JDBCJDBC31“”42JDBCJDBCJDBCJDBCAPIJDBCAPIJDBCJDBCAPIAPIAPIAPIJDBCJDBCODBCODBCAPIAPI562.1JDBC“””“”“”“”“”“”72.2JDBCAPI82.2.2SQL(1)JDBCDBMS(2)ANSISQL112EntryLever92.2.3102.2.4JavaJavaJDBCJavaJavaJavaJava112.2.5JDBCAPIJDBCAPI122.2.62.2.7JDBC“Java”JDBCJavaAPIODBCODBCJavaJDBCJDBCJava132.3JDBCAPIAPI“”“”142.4JDBCODBCAPIODBCAPIJavaODBCJDBCJDBC-ODBCJDBC1.JavaODBC2ODBCCAPIJavaAPI3ODBC4JDBCJDBCAPI“Java”152.5/(1)“”1611/172/183JDBC3.1JavaSoftJavaSoftJDBCJDK(1)JDBC(2)JDBC(3)JDBC—ODBC19JavaApplicationJDBCmanagerJDBC_NetDriverJDBC-ODBCBridgeDriverODBCandDBDriverDriverADriverBJDBCAPIJDBCDriverAPI…JDBCImplementationalternativesPublishedprotocolProprietarydatabaseAccessprotocols3JDBC203.2JDBC3.2JDBC44SUNSUNJDBCJDBC4444JDBCJDBC--ODBCODBCAPIJavaJavaJavaJavaJavaJava214422JDBCJDBCjdbcDriverManagerDriverManager1JdbcOdbcDriverclassClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);2SQLServerDriverClass.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver);//java.sql.DriverManager.registerDriver(newcom.microsoft.jdbc.sqlserver.SQLServerDriver());//233OracleDriverClass.forName(“oracle.jdbc.driver.OracleDriver);//java.sql.DriverManager.registerDriver(neworacle.jdbc.driver.OracleDriver());//4MySQLDriverClass.forName(“com.mysql.jdbc.Driver);//java.sql.DriverManager.registerDriver(newcom.mysql.jdbc.Driver());//24Connectioncon=java.sql.DriverManager.getConnection(BDurl,user,password);BDurlJDBCURLjdbc:drivertype:driversubtype://paramentersDrivertypedriversubtypeparamentersIP25JDBCURL1JDBC-ODBCDriverBDurl=“jdbc:odbc:datasource”;//2OracleBDurl=“jdbc:oracle:thin:@localhost:1521:sid3SQLServeBDurl=“jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=BookDB;//4MySQLBDurl=“jdbc:mysql://localhost:3306/BookDB;//264JDBCAPI4.1JDBCjava¾4.1.1Applets¾4.1.2.Applications274.1.1AppletsJavaappletwebapplet(1)applet(2)Internetapplet3)appletTrustedappletsJavaapplet284.1.2.ApplicationsJavaJAVAJAVAJAVAAPPLICATIONSJAVA5295ApplicationJavaJDBCLAN304.2JDBCJavaapplicationJavaappletJavaapplet3111.4.211.4.2.2JDBCJavaJavaappletJavaJDBCappletsun.sql.DriveDrive11.4.2.3(1)TCP(2)3211.4.3JDBC11.611.6336JDBCAPIDriverManagerConnectionConnectionConnectionStatementStatementStatementStatementResultSetResultSetResultSet345JDBC5.15.15.25.25.35.35.45.45.55.55.65.65.75.7JDBCJDBC355.136JDBC-ODBC1JDBCDriverManager,()Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);2kk_sConnectioncon=DriverManager.getConnection(jdbc:odbc:kk_s);3SQLStatementStatementstmt=con.createStatement();stmt.execute(selectnamefromstudentwhereage18;);375.2JDBCStatement,PreparedStatementCallableStatement1)Statement1.Statement2.3.4.Statement2)PreparedStatement1.PreparedStatement2.385.23.4.CallableStatement3911.5.3r“”“”“”“”“”2)4011.5.411.5.4.1CustomeerFirsrName”LiAddressBeijing:stmt.executeUpdate(UPDATECustomerSETAddress='Beijing'WHEREFristName=Li);Customerstmt.executeUpdate(DELECTFROMCustomerWHEREAddress='Beijing');stmt.executeUpdate(INSERTINTOCustomer(CustometID,FirstName)VALUES(11,'Liu'););4111.5.411.5.4.2anotherIDNamestmt.executeUpdate(CREATETABLEanother(IDINTEGER,NameVARCHAR(20));11.5.4.3anotherAddressstmt.executeUpdate(ALTERTABLEanotherADDCOLUMNAddressVARCHAR(50));stmt.executeUpdate(ALTERTABLEanotherDROPCOLUMNAddress);4211.5.44311.5.54411.5.5SQLUPDATEStringIntSQLUPDATEPREPAREDSTATEMENTPSTMT=CON.PREPARESTATEMENT(UPDATEtableSETm=?WHETEx=?);c.setString(1,text);for(intI=0;I10;I++);{Pstmt.setInt(2,I);Pstmt.executeUpdate();}4511.5.511.5.5.2CallableStatement11.5.5.311.5.5.411.5.5.54611.5.6,JDBC,,.JDBCJDBC4711.5.6,Connection,.JDBC4811.5.64911.5.7JDBCJDBCJavaSQLExceptionJDBCSQLExceptionSQLWarningDatatruncation.5011.5.7JDBC5111.5.7JDBC5211.5.7JDBC5311.5.7JDBC5411.5.7JDBC““”“”“”“”5511.5.7JDBC””5611.6JAVAJDBC2C/S124JDBCJDBC2C/SODBCCDBMSODBCODBCODBCSQLODBCODBCSQLJDBCJDBC-ODBCJavaODBC11.711.75711.75811.6.2JAVAJDBC11.811.85911.84JDBCC/S6011.761IDNameagesexphone12786574582255611852462Jbuilder2database.jprMainFrame.javaMainFrame.javadesignGridControl“”“”“”“”GridControlsubfocusChangedGridControl“”“”“”“”“”MainFrame.java1111--551111--556311-5646511-106611-116711-126811-136911.7.3JDBCAPI7011.7.4“”7111.7.51.“”“”“”7211.7.5“”4.“”“”7311.7.674JavaJDBCJDBCODBCJavaJDBCJDBCSQL75
本文标题:Java与数据库的连结
链接地址:https://www.777doc.com/doc-5316426 .html