jsp_servlet(4)
/*
author="Evangelion"
jdbc.java做的是bean 在jsp中使用
*/
package com.tom.javaBean;
import java.sql.*;
public class JDBC {
private Connection con;
private PreparedStatement pre;
public ResultSet rs;
private String inputName;
private String selectTime;
private String vacationText;
private String selectDays;
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载驱动
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void getConnection() {
String url = "jdbc:oracle:thin:@10.19.115.131:1521:orcl";
String username = "raop";
String password = "raop12345";
try {
con = DriverManager.getConnection(url, username, password); // 连接数据库
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet doQuery(String text1) { // 做查询
this.getConnection(); // 先连接
try {
pre = con.prepareStatement("select * from tomigjun_vacation where user_name=?");
pre.setString(1, text1);
rs = pre.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public int doUpdate(String text1,String text2,String text3,String text4) {//提交insert
this.getConnection();
int count = 0;
try {
pre = con.prepareStatement("insert into tomigjun_vacation values (?,?,?,?)");
pre.setString(1, text1);
pre.setString(2, text2);
pre.setString(3, text3);
pre.setString(4, text4);
count = pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
// public int doUpdate(DbOperator dba) {//提交insert
// this.getConnection();
// int count = 0;
//
// try {
// pre = con.prepareStatement("insert into pclink values (?,?,?)");
// pre.setInt(1, 1);
// pre.setInt(2, 0);
// pre.setString(3, dba.getVacationText());
//
// count = pre.executeUpdate();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// return count;
// }
// public int doUpdate(String sql, Object[] args) {//提交多个insert语句
// this.getConnection();
// int count = 0;
// try {
// pre = con.prepareStatement(sql);
// for (int i = 0; i < args.length; i++) {
// pre.setObject(i + 1, args[i]);
// }
// count = pre.executeUpdate();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// return count;
// }
public void closeQuery() {
try {
rs.close();
pre.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeUpdate() {
try {
pre.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public String getSelectDays()
{
return this.selectDays;
}
public void setSelectDays(String selectDays)
{
this.selectDays=selectDays;
}
public void setInputName(String inputName)
{
this.inputName=inputName;
}
public void setSelectTime(String selectTime)
{
this.selectTime=selectTime;
}
public void setVacationText(String vacationText)
{
this.vacationText=vacationText;
}
public String getSelectTime()
{
return this.selectTime;
}
public String getVacationText()
{
return this.vacationText;
}
public String getInputName()
{
return inputName;
}
public void qall(String text1)
{
doQuery(text1);
}
public void insertInfo(String text1,String text2,String text3,String text4)
{
doUpdate(text1,text2,text3,text4);
}
}