<?xml version="1.0" encoding="gb2312"?>

<!-- RSS generated by oioj.net on 4/16/2004 ; 感谢LeXRus提供 RSS 2.0 文档; 此文件可自由使用，但请保留此行信息 --> 
<!-- Source download URL: http://blogger.org.cn/blog/rss2.asp       -->
<rss version="2.0">

<channel>
<title>wendyneil的博客</title>
<link>http://blogger.org.cn/blog/blog.asp?name=wendyneil</link>
<description>wendyneil的博客</description>
<copyright>blogger.org.cn</copyright>
<generator>W3CHINA Blog</generator>
<webMaster>webmaster@blogger.org.cn</webMaster>
<item>
<title><![CDATA[JDBC数据源和连接池]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=wendyneil&amp;id=46715</link>
<author>wendyneil</author>
<pubDate>2009/7/29 10:48:42</pubDate>
<description><![CDATA[
<P>//Source:</P>
<P>//《精通Java Web整合开发》 刘斌 编著&nbsp; 电子工业出版社</P>
<P>// MySQL 参考手册</P>
<P><FONT face="Comic Sans MS">在JSP或者Servlet中使用JDBC时，每次使用前要建立连接、用完后又要关闭，这有点麻烦。当用户数量增加时，会在建立连接和销毁连接过程中耗费很多资源。这时我们可以采用数据源和连接池。数据库连接池在应用程序启动时就创建足够多的数据库连接，在JAVA程序需要访问数据库时就可以通过数据源获得一个空闲连接，用完后再释放到连接池中。</FONT></P>
<P><FONT face="Comic Sans MS">下面以Tomcat6.0和MySQL5.0为例讲讲数据源和连接池的配置：</FONT></P>
<OL>
<LI><FONT face="Comic Sans MS">将数据库JDBC Driver复制到tomcat/lib目录下；</FONT></LI>
<LI><FONT face="Comic Sans MS">在tomcat/conf/server.xml中配置数据源和连接池：</FONT></LI></OL>
<P><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Host name="localhost"&nbsp; appBase="webapps"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unpackWARs="true" autoDeploy="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlValidation="false" xmlNamespaceAware="false"&gt;</FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Context path="/WebRoot" docBase="WebRoot" debug="0" crosscontext="true" reloadable="true"&gt;</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Resource name="jdbc/myDataSource" type="javax.sql.DataSource" </FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username="root" password="123" driverClassName="com.mysql.jdbc.Driver" </FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxIdle="30" maxWait="10000"&nbsp;&nbsp;&nbsp;maxActive="100"&nbsp; </FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url="jdbc:mysql://localhost:3306/test?autoReconnect=true"&nbsp;&nbsp;/&gt;</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P><FONT face="Comic Sans MS">&lt;/Context&gt;</FONT></P></BLOCKQUOTE>
<P><FONT face="Comic Sans MS">&lt;/Host&gt;</FONT></P>
<P><FONT face="Comic Sans MS">添加的属性以&lt;Context path=...&gt;开头，置于&lt;host&gt; &lt;/host&gt;之间</FONT></P>
<P><FONT face="Comic Sans MS">其中一些属性简介如下：</FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp; &lt;!-- maxActive: Maximum number of dB connections in pool. Make sure you<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; configure your mysqld max_connections large enough to handle<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all of your db connections. Set to 0 for no limit.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;<BR><BR>&nbsp;&nbsp;&nbsp; &lt;!-- maxIdle: Maximum number of idle dB connections to retain in pool.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set to -1 for no limit.&nbsp; See also the DBCP documentation on this<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and the minEvictableIdleTimeMillis configuration parameter.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;<BR><BR>&nbsp;&nbsp;&nbsp; &lt;!-- maxWait: Maximum time to wait for a dB connection to become available<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in ms, in this example 10 seconds. An Exception is thrown if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this timeout is exceeded.&nbsp; Set to -1 to wait indefinitely.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;<BR><BR>&nbsp;&nbsp;&nbsp; &lt;!-- username and password: MySQL dB username and password for dB connections&nbsp; --&gt;<BR><BR>&nbsp;&nbsp;&nbsp; &lt;!-- driverClassName: Class name for the old mm.mysql JDBC driver is<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; org.gjt.mm.mysql.Driver - we recommend using Connector/J though.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &lt;!-- url: The JDBC connection url for connecting to your MySQL dB.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The autoReconnect=true argument to the url makes sure that the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mm.mysql JDBC Driver will automatically reconnect if mysqld closed the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connection.&nbsp; mysqld by default closes idle connections after 8 hours.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;<BR></FONT></P></BLOCKQUOTE>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp; 3. 在web.xml中配置对数据源连接池的引用</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"><PRE><FONT face="Comic Sans MS">&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4"&gt;
  &lt;description&gt;MySQL Test App&lt;/description&gt;
  &lt;resource-ref&gt;
      &lt;description&gt;DB Connection&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/myDataSource&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
&lt;/web-app&gt;</FONT></PRE></BLOCKQUOTE><PRE dir=ltr><FONT face="Comic Sans MS">   4.  在JSP或Servlet中通过数据源访问数据库</FONT></PRE>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"><PRE dir=ltr><FONT face="Comic Sans MS">&lt;%@ page language="java" import="java.util.*" pageEncoding="gb2312"%&gt;<BR>&lt;%@ page import="java.sql.*"%&gt;<BR>&lt;%@ page import="javax.sql.DataSource"%&gt;<BR>&lt;%@ page import="javax.naming.*"%&gt;</FONT></PRE><PRE dir=ltr><FONT face="Comic Sans MS">&lt;html&gt;<BR>&nbsp;&lt;head&gt;&lt;title&gt;通过数据源访问数据库&lt;/title&gt;<BR>&nbsp;&lt;/head&gt;<BR>&nbsp;&lt;body&gt;<BR>&nbsp;&nbsp;&lt;h2&gt;通过数据源访问数据库&lt;/h2&gt;&lt;hr&gt;<BR>&nbsp;&nbsp;&lt;%<BR>&nbsp;&nbsp;&nbsp;Connection con=null;<BR>&nbsp;&nbsp;&nbsp;Statement stat=null;<BR>&nbsp;&nbsp;&nbsp;ResultSet rs=null;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//从数据源连接池取得连接<BR>&nbsp;&nbsp;&nbsp;Context ctx=new InitialContext();<BR>&nbsp;&nbsp;&nbsp;DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/myDataSource");<BR>&nbsp;&nbsp;&nbsp;con=ds.getConnection();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//查询数据库表<BR>&nbsp;&nbsp;&nbsp;stat=con.createStatement();<BR>&nbsp;&nbsp;&nbsp;String sql="select * from user";<BR>&nbsp;&nbsp;&nbsp;rs=stat.executeQuery(sql);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;while(rs.next())<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.println("&lt;li&gt;账号："+rs.getString(2).trim());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.println("密码："+rs.getString(3)+"&lt;/li&gt;");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;rs.close();<BR>&nbsp;&nbsp;&nbsp;stat.close();<BR>&nbsp;&nbsp;&nbsp;con.close();<BR>&nbsp;&nbsp;%&gt;<BR>&nbsp;&lt;/body&gt;<BR>&lt;/html&gt;&nbsp;</FONT></PRE></BLOCKQUOTE>
<P><FONT face="Comic Sans MS"></FONT>&nbsp;</P>
<P><FONT face="Comic Sans MS">&nbsp;&nbsp; 5. 在tomcat下，可以通过http://localhost:8080/WebRoot/dbtest.jsp访问到数据库 </FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;</FONT></P></BLOCKQUOTE>]]></description>
</item><item>
<title><![CDATA[JDBC API简介（看看java.sql中的一些接口和类们）]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=wendyneil&amp;id=46702</link>
<author>wendyneil</author>
<pubDate>2009/7/28 11:28:49</pubDate>
<description><![CDATA[<P>//Source:</P>
<P>//《精通Java Web整合开发》 刘斌 编著&nbsp; 电子工业出版社</P>
<P>// MySQL 参考手册 </P>
<P><FONT face="Comic Sans MS">现在我们就对JDBC API作一些简单了解</FONT></P>
<P><FONT face="Comic Sans MS">1. Driver接口和DriverManager类</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P><FONT face="Comic Sans MS">所有的JDBC驱动程序都必须实现Driver接口，DriverManager从它的名字来看便知道它的用途了，用来管理这些Drivers，另外它还为我们提供了建立在这些驱动之上的数据库连接（Connections）</FONT></P>
<P><FONT face="Comic Sans MS">DriverManager的常用方法</FONT></P>
<UL>
<LI><FONT face="Comic Sans MS">void registerDriver(Driver driver) 将指定的JDBC驱动程序注册到DriverManager中去</FONT></LI>
<LI><FONT face="Comic Sans MS">void deregisterDriver(Driver driver) 将指定的JDBC驱动程序从DriverManager中删除</FONT></LI>
<LI><FONT face="Comic Sans MS">Connection getConnection(String url,String user,String password)</FONT></LI>
<LI><FONT face="Comic Sans MS">Connection getConnection(String url) 返回Connection</FONT></LI></UL></BLOCKQUOTE>
<P dir=ltr><FONT face="Comic Sans MS">2. Connection接口</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr><FONT face="Comic Sans MS">Connection常用方法</FONT></P></BLOCKQUOTE>
<UL dir=ltr style="MARGIN-RIGHT: 0px">
<UL>
<LI><FONT face="Comic Sans MS">void close() 关闭该连接</FONT></LI>
<LI><FONT face="Comic Sans MS">void commit() 提交事务</FONT></LI>
<LI><FONT face="Comic Sans MS">Statement createStatement() 建立并返回一个Statement对象</FONT></LI>
<LI><FONT face="Comic Sans MS">DatabaseMetaData getMetaData() 取得数据库的MetaData数据</FONT></LI>
<LI><FONT face="Comic Sans MS">boolean isClosed() 判断该连接是否已经关闭</FONT></LI>
<LI><FONT face="Comic Sans MS">PreparedStatement prepareStatement(String sql) 建立并返回一个PreparedStatement对象</FONT></LI>
<LI><FONT face="Comic Sans MS">void rollback() 事务回滚</FONT></LI>
<LI><FONT face="Comic Sans MS">void setAutoCommit(boolean autoCommit) 设置该Connection对象是否采用自动事务提交模式</FONT></LI></UL></UL>
<P dir=ltr><FONT face="Comic Sans MS">&nbsp;</FONT></P>
<P dir=ltr><FONT face="Comic Sans MS">3. Statement接口</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr><FONT face="Comic Sans MS">Statement对象可以通过Connection对象的createStatement()获得</FONT></P>
<P dir=ltr><FONT face="Comic Sans MS">Statement常用方法</FONT></P>
<UL>
<LI dir=ltr><FONT face="Comic Sans MS">void close() 关闭该Statement对象并释放资源</FONT></LI>
<LI dir=ltr><FONT face="Comic Sans MS">ResultSet executeQuery(String sql) 执行指定的SQl语句并返回一个ResultSet对象</FONT></LI>
<LI dir=ltr><FONT face="Comic Sans MS">int executeUpdate(String sql) 执行指定SQL语句并返回所影响的行数</FONT></LI>
<LI dir=ltr><FONT face="Comic Sans MS">int getMaxRows() 返回该Statement对象所支持的ResultSet对象的最大行数</FONT></LI>
<LI dir=ltr><FONT face="Comic Sans MS">void setMaxRows(int max) 设定该Statement对象所支持的ResultSet对象的最大行数</FONT></LI></UL></BLOCKQUOTE>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">4. PreparedStatement接口</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">建立了与数据库连接后，对于一些动态的SQL语句，可以用PreparedStatement对象执行。PreparedStatement对象可以通过Connection对象的prepareStatement()方法取得：</FONT></P>
<OL>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">使用PreparedStatement对象的prepareStatement(String sql)方法建立一个PreparedStatement对象；</FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">使用PreparedStatement对象的setXXX方法为参数赋值；</FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">使用PreparedStatement对象的executeQuery()执行SQL语句并得到ResultSet对象</FONT></DIV></LI></OL>
<P style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">PreparedStatement对象常用方法如下：</FONT></P>
<UL>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">ResultSet executeQuery()&nbsp; 执行查询并返回ResultSet对象</FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void setDate(int index,Date x)&nbsp; 为指定参数赋java.sql.Date类型值</FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void setDouble(int index,double x)&nbsp; </FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void setInt(int index,int x)</FONT></DIV></LI>
<LI>
<DIV style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void setString(int index,String x)</FONT></DIV></LI></UL></BLOCKQUOTE>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">5. ResultSet接口</FONT></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">查询数据库的终极目标是想得到一个满足条件的结果记录集，然后再对该结果集的数据进行操作，上面所讲的Statement对象和PreparedStatement对象执行指定SQL语句后将返回代表结果记录集的ResultSet对象，此对象除了包含查询结果的记录集外，还维护着一个指向当前数据行的游标，通过该游标的位置来达到操作不同记录集的目的。</FONT></P>
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">ResultSet对象的常用方法如下：</FONT></P>
<P style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS" color=#ff0000>在ResultSet对象中的记录号和字段号都是从1开始的！！！</FONT></P>
<UL>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean absolute(int row) </FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void afterLast()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void beforeFirst()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">void close()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean first()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean last()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean next()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean previous()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean isAfterLast()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean isBeforeFirst()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean isFirst()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean isLast()</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">int getRow()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回游标指向的记录号</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean getBoolean(int columIndex)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">boolean getBoolean(String columnName)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">Date getDate(int columnIndex)&nbsp; 从当前行中指定序号的字段中取得一个java.sql.Date类型的值</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">Date getDate(String columnName)&nbsp; 从当前行指定的字段名中取得一个java.sql.Date类型的值</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">double getDouble(int columnIndex)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">double getDouble(String columnName)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">int getInt(int columnIndex)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">int getInt(String columnName)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">long getLong(int columnIndex)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">long getLong(String columnName)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">String getString(int columnIndex)</FONT></LI>
<LI dir=ltr style="MARGIN-RIGHT: 0px"><FONT face="Comic Sans MS">String getString(String columnName)</FONT></LI></UL></BLOCKQUOTE>]]></description>
</item><item>
<title><![CDATA[JDBC基础知识]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=wendyneil&amp;id=46701</link>
<author>wendyneil</author>
<pubDate>2009/7/28 10:55:58</pubDate>
<description><![CDATA[<P>//Source:</P>
<P>//《精通Java Web整合开发》 刘斌 编著&nbsp; 电子工业出版社</P>
<P>// MySQL 参考手册</P>
<P>// 《JSP2.0 技术手册》 林上杰 林康司 编著 电子工业出版社</P>
<P>这里谈谈刚刚学习的JDBC链接，我是第一次弄这个。</P>
<P>JDBC访问数据库有四个步骤：</P>
<P>&nbsp;&nbsp; 1. 将数据库的JDBC驱动加载到classpath中；</P>
<P>&nbsp;&nbsp; 2. 加载JDBC驱动，并将其注册到DriverManager中：</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 采用Class.forName("……").newInstance():</P>
<OL>
<OL>
<UL>
<LI>其中……代表各个数据库的Driver，如MySQL就是com.mysql.jdbc.Driver</LI></UL></OL></OL>
<P>&nbsp;&nbsp; 3. 建立数据库连接，获取Connection对象：</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>以MySQL为例：</P>
<P>String url="jdbc:mysql://localhost:3306/testDB?user=root&amp;password=123&amp;</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>useUnicode=true&amp;characterEncoding=gb2312";</P></BLOCKQUOTE></BLOCKQUOTE>
<P dir=ltr>&nbsp;Connection conn=DriverManager.getConnection(url);</P></BLOCKQUOTE>
<P dir=ltr><U><STRONG>这里我们要详细讲讲其中的一些methods</STRONG></U></P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>Class.forName("……").newInstance</P>
<P dir=ltr>这里我们为什么要在加载完驱动程序后，再调用newInstance()呢？是因为加载驱动时可能会出现“Driver not found”的错误提示信息，因为在用Class.forName()加载时，会碰到JDBC规范与某些JVM产生问题，因此我们采用示例的程序。</P>
<P dir=ltr>getConnection()</P>
<P dir=ltr>这个方法除了上面的用法外，还有一种：</P>
<P dir=ltr>String url="jdbc:mysql://localhost:3306/testDB";</P>
<P dir=ltr>String user="root";</P>
<P dir=ltr>String password="123";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //这里我们数据库root用户密码设为123</P>
<P dir=ltr>Connection conn=DriverManager.getConnection(url,user,password);</P></BLOCKQUOTE></BLOCKQUOTE>
<P dir=ltr>&nbsp;&nbsp; 4. 建立Statement对象或PreparedStatement对象：</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>//建立Statement对象</P>
<P dir=ltr>Statement stmt=conn.createStatement();&nbsp; </P>
<P dir=ltr>//建立PreparedStatement对象</P>
<P dir=ltr>String sql="select * from users where userName=?and password=?";</P>
<P dir=ltr>PreparedStatement pstmt=conn.prepareStatement(sql);</P>
<P dir=ltr>pstmt.setString(1,"admin");</P>
<P dir=ltr>pstmt.setString(2,"liubin");</P></BLOCKQUOTE></BLOCKQUOTE>
<P dir=ltr>&nbsp;&nbsp; 5. 执行SQL语句：</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>//执行静态SQL查询</P>
<P dir=ltr>String sql="select * from users";</P>
<P dir=ltr>ResultSet rs=stmt.executeQuery(sql);</P>
<P dir=ltr>//执行动态SQL查询</P>
<P dir=ltr>ResultSet rs=pstmt.executeQuery();</P>
<P dir=ltr>//执行insert、update、delete等语句，先定义sql</P></BLOCKQUOTE></BLOCKQUOTE>
<P dir=ltr>&nbsp;&nbsp; 6. 访问结果记录集ResultSet对象：</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>while(rs.next())</P>
<P dir=ltr>{</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>out.println("你的第一个字段内容为："+rs.getString(1));</P>
<P dir=ltr>out.println("你的第二个字段内容为："+rs.getString(2));</P></BLOCKQUOTE>
<P dir=ltr>}</P></BLOCKQUOTE></BLOCKQUOTE>
<P dir=ltr>&nbsp;&nbsp; 7. 依次将ResultSet、Statement、PreparedStatement、Connection对象关闭：</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr>rs.close();</P>
<P dir=ltr>stmt.close();</P>
<P dir=ltr>pstmt.close();</P>
<P dir=ltr>conn.close();</P></BLOCKQUOTE></BLOCKQUOTE>
<P>&nbsp;</P>]]></description>
</item><item>
<title><![CDATA[The Most Common Habits from more than 200 English Papers      SECTION2]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=wendyneil&amp;id=43622</link>
<author>wendyneil</author>
<pubDate>2009/3/9 20:31:50</pubDate>
<description><![CDATA[<P><FONT face="Comic Sans MS">Section 2</FONT></P><FONT face="Comic Sans MS">
<P><BR></FONT>1) Some words have identical singular and plural forms and do not need an s added on to make them plural. These words include:<BR>&#8226; literature (when referring to research)<BR>&#8226; equipment,<BR>&#8226; staff (referring to a group of people)<BR>&#8226; faculty<BR>2) Avoid redundancy in the following types of phrases frequently used by Chinese English writers<BR>Instead of&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Say&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Or say<BR>Research work&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Research&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Work<BR>Limit condition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Limit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; condition<BR>Knowledge memory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Knowledge&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Memory<BR>Sketch map&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sketch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; map<BR>Layout scheme&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Layout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scheme<BR>Arrangement plan&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arrangement&nbsp;&nbsp;&nbsp;&nbsp; plan<BR>Output performance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Output&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; performance<BR>Simulation results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simulation<BR>Knowledge information&nbsp;&nbsp;&nbsp; Knowledge&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; information<BR>Calculation results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; calculation<BR>Application results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application</P>
<P><BR>3) Certain words demand that the noun they modify is plural. These include different, various, and number words.<BR>Don’t write&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Instead write<BR>Different node&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Different nodes<BR>Various method&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Various methods<BR>Two advantage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Two advantages<BR>Fifteen thermocouple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fifteen thermocouples</P>
<P><BR>4) Never begin an English sentence with abbreviations and Arabic numerals such as Fig.and 8. Instead write Figure and Eight.</P>
<P><BR>5) Do not write ‘by this way’. Instead write ‘by doing this’, or ‘using this method’.</P>
<P><BR>6) Never write ‘How to…’ at the beginning of a sentence. (Don’t say it ither.)</P>
<P>No How to find the optimal parameter is the main objective.</P>
<P>Yes Determining how to find the optimal parameter is the main objective.</P>
<P><BR>7) Do write ‘the results are shown in Figure 2’. Do not write ‘the results are showed as Figure 2’.</P>
<P><BR>8) Italicize variables appearing in the text to differentiate them from words. This is especially important when the variables are English alphabets. Write ‘The graph shows t, a, and C as a function of time’. Do not write ‘The graph shows t, a, and C as a function of time’.</P>
<P><BR>9) Refrain from using the word obviously in a technical paper in the following way No Obviously, detecting regimes by means of PMH maps is a novel method.[8]<BR>Yes Detecting regimes by means of PMH maps is a novel method.[8]</P>
<P><BR>10) International papers should not use location dependant terms such as ‘at home’, abroad’, ‘here’, ‘our country’ because the reader most likely is not Chinese and not in China. Instead, write ‘in China’.</P>
<P><BR>11) Avoid overusing the phrases ‘that is to say’ and ‘namely’. Instead, try to convey your meaning in one sentence.</P>
<P><BR>12) Do not use ‘too’ at the end of a written sentence, especially in a technical paper.</P>
<P>&nbsp;</P>
<P>APPENDIX A</P>
<P><BR>1. LIN Fushen, MENG Guang, ‘Dynamic Behavior of an Unbalanced and Warped Jeffcott Rotor with Asymmetric Stiffness’, The State Key Lab of Vibration, Shock and Noise Shanghai JiaotongUnversity, Shanghai 200030, P.R. China, Institute of Vibration Engineering Northwester Polytechnic University, Xi’an 710072, CHINA, 2003<BR>2. ZHANG Yuping, JIANG Shouwei, ‘Review and Analysis of 3D-Model Reconstruction and Application’, Shanghai Jiaotong University, School of Mechanical and Dynamic Engineering,2003<BR>3. DU Shouji, ‘Long Distance Box-bridge Jacking Research: Report of Starting Research’,Shanghai Jiaotong University, Shijiazhuang Municipal Traffic Project Provided a loan by World Bank, Contract number: TA3.1.4, 2003<BR>4. ZHANG Wenqiang, YAN Heqing, HUANG Xuemei, WEI Bin, and WANG Chengtao, ‘3D Modeling and Rapid Prototyping for Dentition Defect Restoration’, School of Mechanical Engineering, Shanghai JiaoTong University, Shanghai 200030, China, The Ninth People’s Hospital, Attached to Shanghai Second Medical University, Shanghai 200011, China, 2003<BR>5. ZHANG YuPing, JIANG Shouwei, YIN Zhongwei, ‘A Generic Approach for Leather Nesting with an Heuristic Simulated Annealing Based Genetic Algorith’, Shanghai JiaoTong University School of Mechanical &amp; Dynamic Engineering, Huashan Road 1954, Shanghai,200030, 2003<BR>6. HU Xin, XI JunTong, JIN Ye, ‘Shape analysis and parameterized modeling of a hip joint’,Institute of Computer Integrated Manufacturing, Shanghai Jiaotong University, Post Code 200030, Shanghai, China, 2003<BR>7. LI LiJun, JIN XianLong, LI YuanYin, WEI JinQiao, WU WeiWei, ‘A Parallel Solver for Structural Modal Analysis’, High Performance Computing Center, Shanghai JiaoTong University, Republic of China, 2003<BR>8. CHEN YongGuo, TIAN ZiPing, MIAO ZhengQing, ‘Application of Time-frequency Analysis to Fluidization Regimes Recognition in Circulating Fluidized Beds’, School of Mechanical and Power Engineering, Shanghai Jiao Tong University, Dongchuan Road 800,Shanghai, P.R. China, 200240, 2003<BR>9. REN ShaoYun, ZHANG JianWu, GAO ChangYun, ‘Modeling and Simulation Analysis of the Torsional Vibration of a FR Driveline System’, School of Mechanical Engineering,Shanghai Jiaotong University, 2003<BR>10. WU LiJun, CHEN HuiEr, ‘Mathematical Model for on-line Prediction of Bottom and Hearth of Blast Furnace by Particular Solution Boundary Element Method’, Department of Power and Mechanical Engineering, Shanghai JiaoTong University, Shanghai, 200030, People’s Republic of China, 2003.<BR>11. JING XueDong, ZHANG GuoQing, PU GengQiang, WANG ChengTao, XU BinShi, ZHU Sheng, ‘Study on Architecture of Remanufacturing System’, School of Mechanical Engineering, Shanghai Jiao Tong University, Shanghai, China, Surface Engineering Institute, Beijing, China<BR>12. CAI XiaoPing, JIN Chen, WU JunBiao, HIRAOKA Sumito, CHEN ShaoLin, ‘Application of Partial Singular Value Decomposition Analysis to Location of Vibration Sources of Elevator’,1. State Key Laboratory of Vibration, Shock &amp; Noise, Shanghai Jiao Tong University, Shanghai, China, 200030, 2. Fujitec CO., Ltd. Osaka, 547-8510, Japan, 2003<BR>13. YE Yao, LIAN ZhiWei, HOU ZhiJian, ‘Heat Exchange Analysis of Cooling Coils Based on a Dynamic Model’, Institute of Refrigeration and Cryogenics, Shanghai Jiao Tong University,Shanghai, 200030, China<BR>14. NIU XinWen, DIN Han, XIONG YouLun, ‘Assembly Plans Generation Based on Precedence Graphs’, School of Mechanical Engineering, Shanghai JiaoTong University, Shanghai</P>
<P>APPENDIX B</P>
<P><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/200939203120339.JPG" border=0></P>]]></description>
</item>
</channel>
</rss>