농부와 컴퓨터/JAVA & JSP

[개발환경] JDK1.5 / Tomcat 5.5 / MySQL 5.0 / DBCP 개발환경 설정

금오귤림원 2006. 3. 11. 00:56

JSP / JAVA 개발 환경의 설정은 정말이지 너무 힘들어!

http://planet.daum.net/chrkang (제주원시인의 맛 좀 볼래요?)

1. JAVA Standalone development environment

-------------------------------------------

1) JDK Version : JDK 1.5.0_06 ( JAVA Software Development Kit )

2) JRE Version : JRE 1.5.0_06 ( JAVA RunTime )

3) Database Server & version : MySQL 5.0.18

4) Purpose : Using Connection Pool with Jakarta DBCP API for MySQL database server

5) Test Program

가. Database Connection POOL Configuration file.

<object class="org.apache.commons.dbcp.PoolableConnectionFactory"

xmlns="http://apache.org/xml/xmlns/jakarta/commons/jocl">
<object class="org.apache.commons.dbcp.DriverManagerConnectionFactory">
<string value="jdbc:mysql://localhost:3306/DatabaseName?

useUnicode=true&characterEncoding=euc_kr" />
<string value="UserName" />
<string value="Password" />
</object>
<object class="org.apache.commons.pool.impl.GenericObjectPool">
<object class="org.apache.commons.pool.PoolableObjectFactory" null="true" />
<int value="10" />
<byte value="1" />
<long value="10000" />
<int value="10" />
<int value="3" />
<boolean value="true" />
<boolean value="true" />
<long value="600000" />
<int value="5" />
<long value="3600000" />
<boolean value="true" />
</object>
<object class="org.apache.commons.pool.KeyedObjectPoolFactory" null="true" />
<string null="true" />
<boolean value="false" />
<boolean value="true" />
</object>


나. Java Source Program

package info.tobe4u.Test;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JOCLPoolingDriverExample

{

public static void main(String[] args)

{

System.out.println("인수 0 = " + args[0]);
System.out.println("인수 1 = " + args[1]);
System.out.println("--------- OK ---------------");

Connection conn = null;
Statement stmt = null;
ResultSet rset = null;

try

{
System.out.println("Creating connection.");
conn = DriverManager.getConnection(args[0]);
System.out.println("--------- OK ---------------");

System.out.println("Creating statement.");
stmt = conn.createStatement();
System.out.println("--------- OK ---------------");

System.out.println("Executing statement.");
rset = stmt.executeQuery(args[1]);
System.out.println("--------- OK ---------------");

System.out.println("Results:");
int numcols = rset.getMetaData().getColumnCount();


while(rset.next())

{
for(int i=1;i<=numcols;i++)

{
System.out.print("\t" + rset.getString(i));
}


System.out.println("");
}
}

catch(SQLException e)

{
e.printStackTrace();
}

finally

{
try { rset.close(); } catch(Exception e) { }
try { stmt.close(); } catch(Exception e) { }
try { conn.close(); } catch(Exception e) { }
}
}
}

6. Compile Option :

javac -cp ../../classes -d ../../classes $(FileName)

7. Runtime Option :

java -classpath ../../classes

-Djdbc.drivers=com.mysql.jdbc.Driver:org.apache.commons.dbcp.PoolingDriver

info.tobe4u.Test.$(FileNameNoExt)

"jdbc:apache:commons:dbcp:/FarmCitrus"

"SELECT * FROM Member"

8. Generation Exception

가. Java.sql.SQLException : No suitable Driver

가) JDBC Driver for MySQL(Connector/J : com.mysql.jdbc.Driver) is not installed.

- Download mysql-connector-java-3.1.12.zip file at

http://www.mysql.com/products/connector/j/ or

Direct Download ( Click hear! )

- Extract mysql-connector-java-3.1.12-bin.jar file to $${JAVA_HOME}/jre/lib/ext

directoy or ${JRE_HOME}/lib/ext directory.

나) Jakarta DBCP Library is not installed

- Download commons-dbcp-1.2.1.zip file at

http://ftp.apache-kr.org/jakarta/commons/dbcp/binaries/commons-dbcp-1.2.1.zip

- Download commons-pool-1.2.zip file at

http://ftp.apache-kr.org/jakarta/commons/pool/binaries/commons-pool-1.2.zip

- Download commons-collections-3.1.zip file at

http://ftp.apache-kr.org/jakarta/commons/collections/binaries/commons-collections-3.1.zip

- Extract commons-dbcp-1.2.1.jar, commons-pool-1.2.jar, commons-collections-3.1.jar file

from each downloded .zip file, and put them to ${JRE_HOME}/lib/ext dir. or

${JAVA_HOME}/jre/lib/ext directory.

나. Java.sql.SQLException : Configuration file not found

- Configuration file of Database Connection Pool is not located proper classpath or not prepared.

- if Configuration file is not prepared yet, Write the configuration file and put to proper location.

case of me, put the file to ${JRE_HOME}/classes.

if the directory not appear on ${JRE_HOME}, just make the directory(classes) and put it there.

다. java.sql.SQLException: You have an error in your SQL syntax; check the manual that

corresponds to your MySQL server version for the right syntax to use near '&'?6;

4E46G8E2F8G2E8FH?GF??!(??' at line 1

- [Configuration.jocl(in this case, FarmCitrus.jocl)] file is not appropriate.

- refer to next statement.

가) inappropriate example

.

.

<object class="org.apache.commons.dbcp.DriverManagerConnectionFactory">
<string value="jdbc:mysql://localhost:3306/DatabaseName?

useUnicode=true&characterEncoding=euc-kr" />
<string value="UserName" />
<string value="Password" />
</object>

.

.

나) appropriate example

.

.

<object class="org.apache.commons.dbcp.DriverManagerConnectionFactory">
<string value="jdbc:mysql://localhost:3306/DatabaseName?

useUnicode=true&characterEncoding=euc_kr" />
<string value="UserName" />
<string value="Password" />
</object>

.

.

라. java.sql.SQLException : could not parse configuration file

- the XML parser that included in JDK or JRE is not appropriate. you must change/alternate/

replace the associated XML parser.

in my case, refer next lines.

- Download Xerces-J-bin.2.8.0.zip file at

http://www.apache.org/dist/xml/xerces-j/Xerces-J-bin.2.8.0.zip

- Extract resolver.jar, xercesImpl.jar, xml-apis.jar file to ${JAVA_HOR}/jre/lib/ext directory or

${JRE_HOME}/lib/ext directory.