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);
 }


}

 

转载于:https://www.cnblogs.com/tom38/p/3414204.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值