±Û¾´ÀÌ :¼ÕÁØÇü 2000³â 3¿ù 03ÀÏ 15:29:32
¾È³çÇϼ¼¿ä ¼ÕÁØÇüÀÔ´Ï´Ù.
Linux Apache Web server(Jserv module)+JSDK2.0+JDK1.2+PostgreSQL
->ÀÌ·± ȯ°æ¿¡¼ SevletÀ» testÁßÀε¥, error log fileÀ» º¸´Ï±î JDBC driver loading Error....¸¸ °è¼Ó¶ß³×¿ä! ¾î°¼Àϱî¿ä?(Á¦°¡ DBÂÊÀº ²ÎÀ̶ó..)
¿©±âºÎÅÍ´Â ¹®Á¦ÀÇ ServletÁß Database ClassÀÇ ¼Ò½ºÀÔ´Ï´Ù.
------------------------------------------------------
import java.sql.*;
import java.util.*;
// µ¥ÀÌÅͺ£À̽º ÃʱâÈ
public class Database
{
String dbName = "BBS";
String postgreSQLDriver = "postgresql.Driver";
String postgreSQLURL =
"jdbc:postgresql:" + dbName ;
String user = "webmaster";
String password = "citech";
Properties props = null;
public static Connection con = null;
Statement stmt = null;
public Database()
{
try
{
props = new Properties();
props.put( "user" , "webmaster" );
props.put( "password" , "citech" );
Class.forName( "postgresql.Driver" );
con = DriverManager.getConnection( "jdbc:postgresql:" + dbName , props );
if( con == null )
{
System.out.println("DEBUG >> class Database : Constructor ==> con is null " );
}
else
System.out.println("DEBUG >> class Database : Constructor ==> con is NOT null " );
}
catch( Exception e)
{
System.err.println("JDBC driver loading Error....");
}
}
public static Connection getConnection()
{
try
{
if( con == null )
{
con = DriverManager.getConnection( "jdbc:postgresql:");//Á¦°¡ ¾Ë±â·Î´Â getConnection( "jdbc:postgresql:" + dbName)ÀÌ°Ô ¸ÂÀ»°Í °°Àºµ¥ ,ÀÌ·¸°ÔÇϸé dbNameÀÌ nonstatic variableÀ̶ó´Â error°¡ ¶ß´Â±º¿ä.....
}
}
catch( SQLException e)
{
System.err.println( "DEBUG>> class Database:getConnection() > Exception = " + e.toString() + " occurred" );
}
return con;
}
public static Statement getStatement()
{
Statement temp = null;
try
{
temp = con.createStatement();
}
catch( SQLException e)
{
System.err.println("class Database : SQLException occured...");
}
return temp;
}
public static PreparedStatement getPreparedStatement( String query )
{
PreparedStatement temp = null;
try
{
temp = con.prepareStatement( query );
}
catch( SQLException e )
{
System.err.println("DEBUG>> class Database: getPreparedStatement > SQLException occured.." );
}
return temp;
}
public static void close()
{
try
{
if( con != null )
con.close();
}
catch( SQLException e)
{
System.err.println("DEBUG>> class Database: close() > SQLException occurred..." );
}
}
}