JAVA ????????? - PowerPoint PPT Presentation

About This Presentation
Title:

JAVA ?????????

Description:

java jdbc jdbc java – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 15
Provided by: 603
Category:
Tags: java | connection | java | jdbc

less

Transcript and Presenter's Notes

Title: JAVA ?????????


1
JAVA ?????????
  • ???? JDBC

2
JDBC
  • JAVA???????????,???????????,???,??,?????
  • ???????????DBMS???????JDBC-ODBC Bridge?Driver????

3
????
  • Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
    // ????? JDBC Driver
  • String url "jdbcodbcStore"
  • ? Connection conn DriverManager.getConnection
    (url)
  • // ????????????

4
????????
  • ??????????(Statement)????????????,????????SQL?????
    ?,???????????????,??????Statement?
  • Statement stmt conn.createStatement()
  • ????(Table)?SQL???
  • CREATE TABLE Personnel(Name VARCHAR(32), ID
    INTEGER, Salary FLOAT, Gender String)

5
????
  • ??????????????????
  • ?????SQL???
  • Insert Into Personnel Values('Tom', 11, 37000,
    '?')

6
??????
  • ???????,???????????
  • ?????SQL???
  • Select ID, Gender, Name From Personnel
  • ??????,??????????????????Statement?????executeQuer
    y()??????????????ResultSet???

7
????
  • ??????????SQL???
  • UPDATE ??? SET ??? value WHERE ??? LIKE 'value'
  • ????Personnel???,?????Jack?????ID??7?

8
??Join Table
  • ?????????????????,????????????????????????????
  • ????
  • "SELECT Package.senderName, Personnel.Name FROM
    Package, Personnel WHERE Package.ID 10 and
    Personnel.ID 10"

9
Prepared Statements
  • ??????????????SQL??,??Insert??Update,?????????????
    ??????,???Prepared Statements?
  • PreparedStatement insertPackage
    conn.prepareStatement("Insert Into Package Values
    ( ?, 'Simon', ?, ? ,'?')")
  • ??????????????,??????????????,?setXXX()???????????
    ?SQL??,XXX??????,??
  • insertPackage.setString(1, "Dean")
  • insertPackage.setInt(2, 22)
  • insertPackage.setInt(3, 500)
  • ?????
  • insertPackage.executeUpdate()
  • ??????insert????

10
Result Sets???
  • ?????????????,????ResultSet?????????????????,?????
    ??????????,???????????ResultSet???????????????????
    ?,???????????????????????????
  • ???????Function??,???????????,??
  • Statement stmt conn.createStatement(
    ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_R
    EAD_ONLY)
  • ResultSet rs stmt.executeQuery("SELECT ID,
    senderName, State FROM Package where ID lt 30")

11
?Result Sets??????
  • absolute()?????????????????????????????1,????2,..
    ?
  • ?relative()??????????????,?????????????,?????????5
    ?,??relative(2)?????7?
  • ??ResultSet???next()???????????????,??????????????
    ,??????(????)???????
  • ?????????????,??????,??????????????????afterLast()
    ??????????,???previous()???????(????????next()??)?

12
??Result Sets?????????
  • ??????????Result Set???????,??????????????
  • ???????????,????createStatement()???????
  • Statement stmt conn.createStatement(ResultSet.TY
    PE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE)
  • ??updateString()?????Result Set??????
  • ??updateRow()????????????????? (??????????)

13
??Result Sets?????????
  • ??moveToInsertRow()?????????????,????updateXXX()??
    ??????,????insertRow()????????????

14
??Result Sets?????????
  • ????????????????,?????ResultSet??????????????????,
    ????deleteRow()?????
  • ?ResultSet????,???????????????,????????refreshRow(
    )?????????????
Write a Comment
User Comments (0)
About PowerShow.com