日期:2014-05-17 浏览次数:20742 次
package javabean;
import java.sql.*;
public class chuli {
private Connection con;
private Statement stm;
private String drivername="com.mysql.jdbc.Driver";
private String url="jdbc.mysql://127.0.0.1:3306/yonghu";
public chuli(){}
public Connection getCon(){
try {
Class.forName(drivername);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con=DriverManager.getConnection(url,"root","1414519845");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
con=null;
}
return con;
}
public Statement getStm() {
try {
con=getCon();
stm=con.createStatement();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return stm;
}
public int insert(String sql)
{
int num=-1;
if(sql==null)sql="";
try {
stm=getStm();
num=stm.executeUpdate(sql);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return num;
}
public ResultSet select(String sql){
ResultSet rs=null;
if (sql==null) {
sql="";
}
try {
stm=getStm();
rs=stm.executeQuery(sql);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return rs;
}
public void closed(){
try {
if(stm!=null)stm.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
try {
if(con!=null)con.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
<%
String username=request.getParameter("username");
String usersex=request.getParameter("usersex");
String userage=request.getParamete