package com;
import java.sql.*;
public class DBConnection {
Connection con;
public DBConnection(){
String url="jdbc:oracle:thin:@localhost:1521:mis";
// String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=book";
String user="scott";
String password="tiger";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
// Class.forName("com.mircosoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con=DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getConnection(){
return con;
}
}
///
package com;
import java.util.ArrayList;
import java.sql.*;
import actionform.bookform;
public class bookdao {
public ArrayList getSelect(String sql){
ArrayList list= new ArrayList();
DBConnection db=new DBConnection();
Connection con=db.getConnection();
try {
Statement stm= con.createStatement();
ResultSet rs=stm.executeQuery(sql);
while(rs!=null&&rs.next()){
bookform b=new bookform();
b.setId(rs.getString("id"));
b.setAuthor(rs.getString("author"));
b.setTitle(rs.getString("title"));
b.setPublish(rs.getString("publish"));
b.setTime(rs.getString("time"));
b.setPrice(rs.getString("price"));
list.add(b);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public int getadd(String sql){
DBConnection DB= new DBConnection();
Connection con =DB.getConnection();
int i=0;
Statement stm;
try {
stm = con.createStatement();
i=stm.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return i;
}
}