package gbicc.net.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBSrc {
String url="jdbc:oracle:thin:@127.0.0.1:1521:oracle";
public DBSrc()
{
super();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
public Connection getConnection()
{
try
{
return DriverManager.getConnection(url,"src","src");
}
catch (SQLException e)
{
e.printStackTrace();
}
return null;
}
/**
* 增删改
* @param sql
* @return
*/
public int executeUpdate(String sql)
{
try
{
Connection conn=this.getConnection();
Statement stmt=conn.createStatement();
int rows=stmt.executeUpdate(sql);
return rows;
}
catch (SQLException e)
{
e.printStackTrace();
}
return -1;
}
/**
* 查询
* @param sql
* @return
*/
public ResultSet executeQuery(String sql)
{
try
{
Connection conn=this.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
return rs;
}
catch (SQLException e)
{
e.printStackTrace();
}
return null;
}
}