import java.sql.*;
public class BaseDao
{
protected Connection conn=null;
protected PreparedStatement ps=null;
protected ResultSet rs=null;
public Connection getConnection()
{
try
{
Class.forName("oracle.jdbc.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url,"sky","admin");
} catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public void close()
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if(ps!=null)
{
ps.close();
ps=null;
}
if(conn!=null)
{
conn.close();
conn=null;
}
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int executeUpdate(String sql,Object...obj)
{
if(conn==null)
conn=getConnection();
int result=-1;
try
{
ps=conn.prepareStatement(sql);
for (int i = 0; i < obj.length; i++)
{
ps.setObject(i+1, obj[i]);
}
result=ps.executeUpdate();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public void executeQuery(String sql,Object...obj)
{
if(conn==null)
conn=getConnection();
try
{
ps=conn.prepareStatement(sql);
for (int i = 0; i < obj.length; i++)
{
ps.setObject(i+1, obj[i]);
}
rs=ps.executeQuery();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}