JDBC

package com.founder.record.db;

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

/**
 * @时间: Oct 31, 2006 10:45:27 AM
 * @类说明:数据库操作类
 */
public class DBController
{
 private static String url = PropertyFile.getValue("db.url");
 private static String userName = PropertyFile.getValue("db.name");
 private static String userPwd = PropertyFile.getValue("db.password");
 private Connection conn = null;
 private PreparedStatement pstmt_insert = null;
 private String SQL_INSERT = "insert into student (id,name,address) values (?,?,?)";

 public static void main(String[] args) throws SQLException
 {
  DBController dbc = new DBController();
  dbc.getPreparedStatement();
 }

 public void getPreparedStatement() throws SQLException
 {
  try
  {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   conn = DriverManager.getConnection(url, userName, userPwd);
   this.pstmt_insert = this.conn.prepareStatement(SQL_INSERT);
   for (int i = 0; i < 100; i++)
   {
    this.pstmt_insert.setInt(1, i);
    this.pstmt_insert.setString(2, "刘效勤" + i);
    this.pstmt_insert.setString(3, "上地" + i + "号");
    this.pstmt_insert.execute();
    this.pstmt_insert.clearParameters();
    System.out.println("插入" + i + "条");
   }

  } catch (Exception e)
  {
  } finally
  {
   if (this.pstmt_insert != null)
   {
    this.pstmt_insert.close();
   }
   if (this.conn != null)
   {
    this.conn.close();
   }
  }
 }
}

 

 

-------------PropertyFile------------------

 

 

 

package com.founder.record.db;

import java.util.ResourceBundle;

/**
 * @时间: Oct 31, 2006 10:47:13 AM
 * @类说明:获取配置文件内容
 */
public class PropertyFile
{
 public static String getValue(String key)
 {
  String temp = ResourceBundle.getBundle("system").getString(key);
  return temp;
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值