Tuesday June 30, 2009 12:19

Sun One Web Server 7′de Mysql Data Source nasıl tanımlanır

Posted by admin

Bu ayarlar Sun Web Server 7 için geçerlidir. Server.xml dosyasında JDBC Resource tanımlamak için

<jdbc -resource>
    <jndi -name>jdbc/mysql</jndi>
    <datasource -class>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</datasource>
    <min -connections>1</min>
    <max -connections>5</max>
    <property>
      <name>password</name>
      <value>password-here</value>
    </property>
    <property>
      <name>user</name>
      <value>jyri</value>
    </property>
    <property>
      <name>url</name>
      <value>jdbc:mysql://boqueron/dbname</value>
    </property>
</jdbc>

Then I copied mysql-connector-java-3.1.12-bin.jar into $INSTANCE/lib (where $INSTANCE is the top level directory of the specific instance, note that you may need to create the lib directory there if it hasn’t been needed before).

In the web application itself, in web.xml, I configured:

<resource -ref>
<description>JDBC Connection Pool</description>
<res -ref-name>jdbc/mysql</res>
<res -type>javax.sql.DataSource</res>
<res -auth>Container</res>
</resource>
And in sun-web.xml:
<resource -ref>
<res -ref-name>jdbc/mysql</res>
<jndi -name>jdbc/mysql</jndi>
</resource>

That’s it for the configuration. In my servlet code:

Context initContext = new InitialContext();
Context webContext = (Context)initContext.lookup("java:/comp/env");
    DataSource ds = (DataSource) webContext.lookup("jdbc/mysql");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
     ....

Kaynak Jyri Virkki. Konuyla ilgili benzer kaynaklar:

Related Posts:

Comment Form