README
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:7k
源码类别:

mpeg/mp3

开发平台:

C/C++

  1. This is a simple readme describing how to compile and use the jdbc driver.
  2. This isn't a guide on how to use JDBC - for that refer to Javasoft's web site:
  3. http://www.javasoft.com
  4. or the JDBC mailing list:
  5. jdbc@java.blackdown.org
  6. http://www.blackdown.org
  7. For problems with this driver, then refer to the postgres-interfaces email
  8. list:
  9. http://www.postgresql.org
  10. By the time V6.3 is released, full documentation will be on the web, and in
  11. the distribution.
  12. ---------------------------------------------------------------------------
  13. COMPILING
  14. To compile the driver, simply use make in the src/interfaces/jdbc directory.
  15. This will compile the driver, and build a .jar file (Java ARchive).
  16. REMEMBER: once you have compiled the driver, it will work on ALL platforms
  17. that support the JDK 1.1 api or later.
  18. That means you don't have to compile it on every platform. Believe me, I
  19. still hear from people who ask me "I've compiled it ok under Solaris, but it
  20. won't compile under Linux" - there's no difference.
  21. PS: When you run make, don't worry if you see just one or two calls to javac.
  22.     If, while compiling a class, javac needs another class that's not compiled,
  23.     it will compile it automatically. This reduces the numer of calls to javac
  24.     that make has to do.
  25. Possible problems
  26. You may see a message similar to:
  27. postgresql/Driver.java:87: interface java.sql.Connection is an interface. It can't be instantiated.
  28.     return new Connection (host(), port(), props, database(), url, this);
  29. This is caused by not having the current directory in your CLASSPATH. Under
  30. Linux/Solaris, unset the CLASSPATH environment variable, and rerun make.
  31. ---------------------------------------------------------------------------
  32. INSTALLING THE DRIVER
  33. To install the driver, the .class files have to be in the classpath. This can be
  34. done in two ways:
  35. 1: create a directory "postgresql" (and it must be called this) in the current
  36.    directory (or a directory in the class path), and copy all .class files
  37.    into it.
  38. 2: copy the postgres.jar file into a directory, and add it to the classpath.
  39.    ie: under LINUX/SOLARIS (the example here is my linux box):
  40. export CLASSPATH=.:/usr/local/lib/postgresql.jar:/usr/local/jdk1.1.1/lib/classes.zip
  41.    note: in java, .zip and .jar files hold collections of classes.
  42. ---------------------------------------------------------------------------
  43. USING THE DRIVER
  44. To use the driver, you must introduce it to JDBC. Again, there's two ways
  45. of doing this:
  46. 1: Hardcoded.
  47.    This method hardcodes your driver into your application/applet. You
  48.    introduce the driver using the following snippet of code:
  49. try {
  50.   Class.forName("postgresql.Driver");
  51. } catch(Exception e) {
  52.   // your error handling code goes here
  53. }
  54.    Remember, this method restricts your code to just the postgresql database.
  55. 2: Parameters
  56.    This method specifies the driver from the command line. When running the
  57.    application, you specify the driver using the option:
  58. -Djdbc.drivers=postgresql.Driver
  59.    eg: This is an example of running one of my other projects with the driver:
  60. java -Djdbc.drivers=postgresql.Driver finder.finder
  61.    note: This method only works with Applications (not for Applets).
  62.  However, the application is not tied to one driver, so if you needed
  63.  to switch databases (why I don't know ;-) ), you don't need to
  64.  recompile the application (as long as you havent hardcoded the url's).
  65. ---------------------------------------------------------------------------
  66. JDBC URL syntax
  67. The driver recognises JDBC URL's of the form:
  68. jdbc:postgresql:database
  69. jdbc:postgresql://host/database
  70. jdbc:postgresql://host:port/database
  71. Also, you can supply both username and passwords as arguments, by appending
  72. them to the URL. eg:
  73. jdbc:postgresql:database?user=me
  74. jdbc:postgresql:database?user=me&password=mypass
  75. By default, the driver doesn't use password authentication. You can enable
  76. this by adding the argument auth. ie:
  77. jdbc:postgresql:database?user=me&password=mypass&auth=password
  78. or if passing the user & password directly via DriverManager.getConnection():
  79. jdbc:postgresql:database?auth=password
  80. PS: Password authentication is enabled if the value of auth starts with 'p'.
  81.     It is case insensitive.
  82. As of postgresql 6.3, Ident (RFC 1413) authentication is also supported.
  83. Simply use auth=ident in the url.
  84. Also, as of 6.3, a system property of postgresql.auth is supported. This
  85. defines the default authentication to use. The auth property overides this.
  86. ---------------------------------------------------------------------------
  87. That's the basics related to this driver. You'll need to read the JDBC Docs
  88. on how to use it.
  89. POSTGRESQL SPECIFICS
  90. --------------------
  91. Date datatype:
  92. The driver now supports US and European date styles (although it is currently
  93. limited to postgres format).
  94. Basically the US like to format their dates as mm-dd-yyyy, while in Europe,
  95. we like to use dd-mm-yyyy. Postgres supports this by the DateStyle variable.
  96. From psql, you can issue "set datestyle='european';" to set european style,
  97. and "set datestyle='us';" to set the US format. You can see what the current
  98. value for this with "show datestyle;".
  99. The driver now issues the "show datestyle;" query when it first connects, so
  100. any call to ResultSet.getDate() how returns the correct date.
  101. One caveat though: if you change the datestyle from within JDBC, you must also
  102. issue the "show datestyle" query. Without this, the driver will not know of
  103. the change.
  104. ie:
  105. Statement s = db.createStatement();
  106. ...
  107. s.executeUpdate("set datestyle='european'");
  108. s.executeUpdate("show datestyle");
  109. ..
  110. s.close();
  111. ------------------
  112. JDBC supports database specific data types using the getObject() call. The
  113. following types have their own Java equivalents supplied by the driver:
  114. box, circle, lseg, path, point, polygon
  115. When using the getObject() method on a resultset, it returns a PG_Object,
  116. which holds the postgres type, and its value. This object also supports
  117. methods to retrive these types.
  118. Eg: column 3 contains a point, and rs is the ResultSet:
  119. PG_Object o = (PG_Object)rs.getObject(3);
  120. PGpoint p = o.getPoint();
  121. System.out.println("point returned x="+p.x+", y="+p.y);
  122. Also, when using these classes, their toString() methods return the correct
  123. syntax for writing these to the database.
  124. ---------------------------------------------------------------------------
  125. Peter T Mount, January 11 1998
  126. home email: pmount@maidast.demon.co.uk http://www.demon.co.uk/finder
  127. work email: peter@maidstone.gov.uk http://www.maidstone.gov.uk
  128. Adrian Hall
  129.      email: adrian@hottub.org