http://www.verejava.com/?id=16998493339542
下载 Oracle 或者 Mysql Jar 驱动
mysql-connector-java-3.0.10-stable-bin.jar
ojdbc14.jar
package com.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil
{
private Connection conn;//数据库的链接对象
public DBUtil()
{
//加载驱动
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
//打开数据的链接
public Connection openConnection()
{
try
{
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "myspace", "myspace123");
} catch (SQLException e)
{
e.printStackTrace();
}
return conn;
}
//执行 INSERT DELETE UPDATE 的方法
public boolean