在写个jsp注册页,用的MVC控制显示都差不多了 可是在写修改数据库的一个BEAN某处卡住了!想了几天越想越迷糊!哎...java底子不牢啊!代码如下 连接的SQL SERVER数据库 连接和异常BEAN都写好了,卡住的代码如下:
import java.sql.*;
import java.util.Collection;
import java.util.Iterator;
import java.util.ArrayList;
import com.liu.photo.sql.connection.DBconn;
public class usermessage
{
private String ID="";
private String Password="";
private String Name="";
private String Sex="";
private String Age="";
private String PaperNo="";
private String Message="";
public usermessage SqlToObj()
{
usermessage theusers=new usermessage();
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs","sa","sa");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from UserMessage");
while(rs.next())
{
String ID = rs.getString("ID");
String Password = rs.getString("Password");
String Name = rs.getString("Name");
String Sex = rs.getString("Sex");
String Age = rs.getString("Age");
String PaperNo = rs.getString("PaperNo");
String Message = rs.getString("Message");
theusers.setID(ID);
theusers.setPassword(Password);
theusers.setName(Name);
theusers.setSex(Sex);
theusers.setAge(Age);
theusers.setPaperNo(PaperNo);
theusers.setMessage(Message);//将数据项读出并保存到某一对象中 方便jsp页面读值
}
}
catch(Exception e)
{
}
return theusers;
}
public String getID()
{
return ID;
}
public void setID(String id)
{
ID = id;
}
public void insertID()
{
String str="";
}
public void delID()
{
String str="";
}
public String getPassword()
{
return Password;
}
public void setPassword(String password)
{
Password = password;
}
public void updatePassword()
{
String str="";
}
public void insertPassword()
{
String str="";
}
public void delPassword()
{
String str="";
}
public String getName()
{
return Name;
}
public void setName(String name)
{
Name = name;
}
public void updateName()
{
String str="";
}
public void insertName()
{
String str="";
}
public void delName()
{
String str="";
}
public String getSex()
{
return Sex;
}
public void setSex(String sex)
{
Sex = sex;
}
public void insertSex()
{
String str="";
}
public String getAge()
{
return Age;
}
public void setAge(String age)
{
Age = age;
}
public void updateAge()
{
String str="";
}
public void insertAge()
{
String str="";
}
public void delAge()
{
String str="";
}
public String getPaperNo()
{
return PaperNo;
}
public void setPaperNo(String paperNo)
{
PaperNo = paperNo;
}
public void insertPaperNo()
{
String str="";
}
public String getMessage()
{
return Message;
}
public void setMessage(String message)
{
Message = message;
}
public void updateMessage()
{
String str="";
}
public void insertMessage()
{
String str="";
}
public void delMessage()
{
String str="";
}
}
代码中定义的insert del update方法怎么写不是很明白 是否每个方法体都要再连接次数据库 还是重写一个方法只把String传进去?困饶很久啊,有没高手能帮助解决下 最好帮我写掉其中一个方法 或整体修改下!万分感谢