2009-03-16 20:51
浏览 68


during a lecture my professor gave examples of several actions involving databases and the java.sql package. These examples were supposed to be uploaded online in a pdf file, but for some reason the names of all functions and class names aren't displaying with my pdf reader.

I would like to know the equilavents of the following PHP functions in Java:



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duan117890
    duan117890 2009-03-16 20:55

    If you consult the Java API docs appropriate for the version you're using (I'm using JDK 1.5, so it's and click on java.sql, you can see all the classes for Java JDBC access.

    Basically, you create a new Connection to a database with DriverManager, and do a query with Connection.prepareStatement, PreparedStatement.execute() and PreparedStatement.executeQuery() and loop through the resultant ResultSet with and pull the results out with ResultSet.getXXXXX.

    点赞 评论
  • doudang4857
    doudang4857 2009-03-17 01:07

    Working directly with JDBC (java.sql) is verbose and error-prone, especially for beginners, because you need to manually do very repetitive steps, and "finally" close so many database objects (Connections, Statements, ResultSets).

    If you do not mind pulling in an extra dependency, Apache Commons have a nice little wrapper package called DbUtils that makes it easy to run queries and updates (while still staying at the SQL level, as opposed to object-relational mappers that go to a higher level of abstraction).

    点赞 评论
  • dongliu8559
    dongliu8559 2009-11-06 22:35

    If you're just getting started with JDBC, consider working your way through Sun's tutorial at:

    点赞 评论