MyDbBean建立这个BEAN,里面就是连接数据库然后更新数据库就可以了,记得package要跟那个JSP文件的一致
解决方案 »
- 如何删除eclipse中Web项目的SVN信息
- 关于页面静态化的问题
- 如何在JSP中使用JavaScript的省级联查
- Syntax error, insert "AssignmentOperator ArrayInitializer" to complete Expression是什么错误?
- 在一个Action类里放置多个execute版本遇到的问题
- jvm内存溢出
- 求解一个session的小问题
- 一JSP新手的弱问题
- 怎样在jsp中显示Excel???
- asp转换JSP的问题?在线等候
- JSP问题,求教
- 我在公司做过四个月的jsp 我现在想到广东 ,上海 ,北京,等地找工作,开始的工资是??
.....
public void OpenConn(String *,String *,String *){}
public ResultSet executeQuery(String *){}
public void executeUpdate(String *){}至少要有以上三个方法
这样说我不明白?
如果修改成功后,请把你整个注册代码留给我。
我的Email:[email protected] [email protected].
package 文件夹;
import java.sql.*;
import java.util.*;/*连接池类.能够根据要求创建新连接,直到最大连接数为止.*/
public class DBConnPool {
//实际使用中的连接数
private int inUse=0;
//空闲连接
private Vector connections = new Vector();
//连接池名
private String poolname;
//数据库标识
private String dbid;
//驱动程序名
private String drivername;
//数据库账号
private String username;
//数据库密码
private String passwd;
//最大连接数
private int maxconn; public DBConnPool(String poolname, String drivername, String dbid, String username, String passwd, int maxconn) {
this.poolname = poolname;
this.dbid = dbid;
this.drivername = drivername;
this.username = username;
this.passwd = passwd;
this.maxconn = maxconn;
} /*将连接返回给连接池*/
public synchronized void releaseConnection(Connection con) {
// 将指定连接加入到向量末尾
connections.addElement(con);
//连接数减一
inUse--;
} /*从连接池得到一个连接*/
public synchronized Connection getConnection() {
Connection con = null;
if (connections.size() > 0) {
// 获取连接列表中获得第一个连接
con = (Connection) connections.elementAt(0);
connections.removeElementAt(0);
//如果此连接已关闭,则继续获取
try {
if (con.isClosed())
con = getConnection();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
//如果实际使用的连接小于最大连接数,就新创建一个连接
else if (maxconn == 0 || inUse < maxconn) {
con = newConnection();
}
if (con != null) {
//连接数增一
inUse++;
}
//返回一个连接
return con;
} /*创建新的连接*/
private Connection newConnection() {
Connection con = null;
try {
//加载驱动程序
Class.forName(drivername);
//建立连接
con = DriverManager.getConnection(dbid, username, passwd);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
//返回该连接
return con;
} /*关闭所有连接*/
public synchronized void closeConn() {
Enumeration allConnections = connections.elements();
while (allConnections.hasMoreElements()) {
Connection con = (Connection) allConnections.nextElement();
try {
con.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
connections.removeAllElements();
}
}
谢谢 !!!
package DataBase;
import java.sql.*;
import java.util.*;
import java.math.*;public class UserEntity
{
private String id;
private String userName;
private String userPassword;
.
.
.
public static String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
public static String sConnStr = "jdbc:odbc:cart";
public static Connection conn = null;
public String addUser()throws SQLException{ try {
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("UserEntity: " + e.getMessage());
}
try{
conn = DriverManager.getConnection(sConnStr);
String sqlinsert="insert into user(user_name,user_password,user_groupID)values(?,?,?)";
//设置参数
//preStatement.setString(1,query);
//preStatement.setInt(2,(2+1));
//使用excuteUpdate方法执行带参数的sql命令
// preStatement.executeUpdate(); PreparedStatement prepStmt = conn.prepareStatement(sqlinsert); //prepStmt.setString(1,this.id );
prepStmt.setString(1,userName);
prepStmt.setString(2,userPassword);
prepStmt.setInt(3,userGroupID); prepStmt.executeUpdate();
//prepStmt.close();
//conn.close();
}catch(SQLException ex){
System.err.println("UserEntity-addUser executeQuery: " + ex.getMessage());
}
//取得插入用户主键值。
//get the id
//初始化查询字符串 slelectStatment
String selectStatement ="select id " +"from user where user_name=? order by id desc ";
//创建Preparestatement对象prepstmt.
PreparedStatement prepStmt = conn.prepareStatement(selectStatement);
//设置用户名。
prepStmt.setString(1,userName);
//执行查询,并将查询结果存入rs中。
ResultSet rs = prepStmt.executeQuery();
//取得第一条记录
rs.next();
//设置resutl为主键值,并返回。
String result=rs.getString(1); return result;
}
用mysql或者D版oracle/sql-server