thanx for reply
here is my method's code of the class which is communicate to DataBase
public void addUser(User user)
throws SQLException
{
PreparedStatement statement;
String add="Insert into chater "+
"(id,name,nick,status,email_address,contact_no,password) "+
"values(?,?,?,?,?,?,?)";
try{
statement=connection.prepareStatement(add);
statement.clearParameters();
statement.setInt(1,user.getId());
statement.setString(2,user.getName ());
statement.setString(3,user.getNick ());
statement.setByte (4,user.getStatus());
statement.setString(5,user.getEmail ());
statement.setString(6,user.getContactNo());
statement.setString(7,user.getPassword());
statement.executeUpdate();//throws exception here
connection.commit ();
}catch(SQLException sql){
String errorMessage=
"DBConnection:addUser:Record not safe :"+sql;
System.out.println(errorMessage);
throw new SQLException(errorMessage);
}
}
this is my test class snaped code which is working fine
public class testDB{
public void creatUser(){
System.out.println("testDB:main:creating user instance and fill the value");
user=new User();
user.setId(6);
user.setName ("Qasim Shabbir");
user.setNick ("Dragon Dreamz U");
user.setEmail ("
[email protected]");
user.setPassword ("Silent");
user.setStatus((byte)1);
System.out.println("testDB:main:add user to Database");
try{
db.addUser(user);
}catch(SQLException sql){
System.out.println("testDB:main:user not added to Database "+sql);
}
}
public static void main(String arg[]) throws SQLException{
testDB test=new testDB();
test.creatUser ();
}
}
// and here is my real class code which is cozing problem.
public int registerMeToServer(ClientInfo client)
throws RemoteException
{
User user=client.getUser();
int id=db.getMaxId ();
user.setId (id);
Integer key=new Integer(id);
System.out.println("Server:registerMeToServer: user: " +user);
try{
db.addUser (user);
clients.put(key,client);
System.out.println("Server:registerMeToServer: ClientID : " +id);
}catch(Exception e){
System.out.println("Server:registerMeToServer:Error : " +e);
if(clients.contains (key)){
clients.remove (key);
}
id=NOT_FOUND;
}
return id;
}
it throws SQLExcpetion General error
thanking you again
Qasim shabbir
Sun Certified Java Programer