例子:
package net.abc.admin;
import java.io.*;
import java.sql.*;
import java.util.*;
public class ConnectionBean
{
private static Connection conn = null;
public static Connection getConnection()
{
if (conn == null)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection("jdbc:oracle:thin:@"+hostname+":"+port+":"+dbSID,username,password);
} catch(SQLException e)
{
e.printStackTrace();
}
// if(conn == null)
// System.out.println("database connection error");
}
return conn;
}
}