当前位置: 技术问答>java相关
菜鸟求助 程序啊,急!!!!
来源: 互联网 发布时间:2015-06-12
本文导语: 请大家帮忙一下,我想学习jsp 有没有谁有,通过bean来实现对小型数据库的动作啊 我是说把方法都写在bean里面 而jsp只是调用bean来完成数据库的插入,删除,修改,和查询, 数据库用access就可以了,对一个表中的数...
请大家帮忙一下,我想学习jsp
有没有谁有,通过bean来实现对小型数据库的动作啊
我是说把方法都写在bean里面
而jsp只是调用bean来完成数据库的插入,删除,修改,和查询,
数据库用access就可以了,对一个表中的数据进行处理
我说的够明白了吧,我想看看,bean的代码,好吗?
有没有谁有,通过bean来实现对小型数据库的动作啊
我是说把方法都写在bean里面
而jsp只是调用bean来完成数据库的插入,删除,修改,和查询,
数据库用access就可以了,对一个表中的数据进行处理
我说的够明白了吧,我想看看,bean的代码,好吗?
|
好的!
package com.hzs.order;
import java.io.IOException;
import java.sql.*;
import java.util.Vector;
import java.util.*;
public class DBHandle {
// Field
private Vector result = null;
private Connection conn = null;
// Construct
public DBHandle() {
}
// Connect to database
public void connect() throws DBException, IOException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:system/828112@192.9.200.50:1521:mydb");
} catch(ClassNotFoundException E) {
throw new DBException("Connnect: " + String.valueOf(E.getMessage()));
} catch(SQLException E) {
throw new DBException("SQLException: " + String.valueOf(E.getMessage()));
} catch(Exception E) {
throw new DBException("Exception: " + String.valueOf(E.getMessage()));
}
}
public void transaction() throws DBException, IOException {
try {
conn.setAutoCommit(false);
} catch(SQLException E) {
throw new DBException("SQLException: " + String.valueOf(E.getMessage()));
} catch(Exception E) {
throw new DBException("Exception: " + String.valueOf(E.getMessage()));
}
}
// Executes a SQL statement that returns a single ResultSet.
public Vector select(String strQuery) throws DBException, IOException {
result = new Vector();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strQuery);
ResultSetMetaData rsmd = rs.getMetaData();
int FieldNum = rsmd.getColumnCount();
while (rs.next()) {
for (int i = 1; i
package com.hzs.order;
import java.io.IOException;
import java.sql.*;
import java.util.Vector;
import java.util.*;
public class DBHandle {
// Field
private Vector result = null;
private Connection conn = null;
// Construct
public DBHandle() {
}
// Connect to database
public void connect() throws DBException, IOException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:system/828112@192.9.200.50:1521:mydb");
} catch(ClassNotFoundException E) {
throw new DBException("Connnect: " + String.valueOf(E.getMessage()));
} catch(SQLException E) {
throw new DBException("SQLException: " + String.valueOf(E.getMessage()));
} catch(Exception E) {
throw new DBException("Exception: " + String.valueOf(E.getMessage()));
}
}
public void transaction() throws DBException, IOException {
try {
conn.setAutoCommit(false);
} catch(SQLException E) {
throw new DBException("SQLException: " + String.valueOf(E.getMessage()));
} catch(Exception E) {
throw new DBException("Exception: " + String.valueOf(E.getMessage()));
}
}
// Executes a SQL statement that returns a single ResultSet.
public Vector select(String strQuery) throws DBException, IOException {
result = new Vector();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strQuery);
ResultSetMetaData rsmd = rs.getMetaData();
int FieldNum = rsmd.getColumnCount();
while (rs.next()) {
for (int i = 1; i