2个回答
展开全部
你看这个代码是么
import java.sql.*;
public class DataBase
{
private Connection conn;
private Statement stmt;
private ResultSet rs;
public DataBase()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@local:1521","scott","careers");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void executeUpdate(String sql)
{
try
{
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(SQLException e)
{
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
try
{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
public void close()
{
try
{
if(rs != null)
{
rs.close();
}
stmt.close();
conn.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
import java.sql.*;
public class DataBase
{
private Connection conn;
private Statement stmt;
private ResultSet rs;
public DataBase()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@local:1521","scott","careers");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void executeUpdate(String sql)
{
try
{
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(SQLException e)
{
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
try
{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
public void close()
{
try
{
if(rs != null)
{
rs.close();
}
stmt.close();
conn.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
展开全部
如果不是要连接远程access数据库的话 这里有非常详细的介绍 一看就懂http://blog.csdn.net/guofangsky/archive/2006/11/30/1422038.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询