JDBC
来源:互联网 发布:windows 系统编程 编辑:程序博客网 时间:2024/05/21 19:46
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;
}
}
- jdbc
- JDBC
- jdbc
- JDBC
- jdbc
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- jdbc
- JDBC
- JDBC
- jdbc
- zoj 1095 Humble Numbers
- 探求真正的SOA
- 关于WINDOWS CE
- 对FriendFeed的一点思考
- Ajax框架介绍
- JDBC
- 钱这玩意
- 尝试initramfs+ucLibc+busybox
- python整理十八——datetime与time之间的转换
- 浅谈双核,多核对性能的实际提升
- 绝对能够测试你的C语言功力的几个问题!
- 对Friendfriend一点思考之二
- 一个mm写给一个男生的爱情C++脚本
- OLE方式控制WORD生成一个文档,包括自动生成表格