日期:2014-05-16  浏览次数:20566 次

Jdbc封装技术

package org.leadfar;

import java.util.Date;

public class Student {
 private int id;
 private String name;
 private String password;
 private int age;
 private Date birthday;
 private String sex;
 private String memo;
 private String photo;
 private Date reg_times;

 public int getId() {
  return id;
 }

 public void setId(int id) {
  this.id = id;
 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public String getPassword() {
  return password;
 }

 public void setPassword(String password) {
  this.password = password;
 }

 public int getAge() {
  return age;
 }

 public void setAge(int age) {
  this.age = age;
 }

 public Date getBirthday() {
  return birthday;
 }

 public void setBirthday(Date birthday) {
  this.birthday = birthday;
 }

 public String getSex() {
  return sex;
 }

 public void setSex(String sex) {
  this.sex = sex;
 }

 public String getMemo() {
  return memo;
 }

 public void setMemo(String memo) {
  this.memo = memo;
 }

 public String getPhoto() {
  return photo;
 }

 public void setPhoto(String photo) {
  this.photo = photo;
 }

 public Date getReg_times() {
  return reg_times;
 }

 public void setReg_times(Date regTimes) {
  reg_times = regTimes;
 }

}

 

=================================================================================

package org.leadfar;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DB {

 public static Connection getconn() {
  try {
   // 1.加载驱动
   Class.forName("oracle.jdbc.OracleDriver");

  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   System.out.println("驱动加载失败");
  }
  // 2.得到连接
  String url = "jdbc:oracle:thin:@localhost:1521:leadfar";
  Connection conn = null;
  try {
   conn = DriverManager.getConnection(url, "BBS", "BBS");