GeeCON Prague 2014*
The moose likes JDBC and the fly likes SQL Exception: General error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Exception: General error" Watch "SQL Exception: General error" New topic
Author

SQL Exception: General error

Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
can any body know y general error occurs.. wht does it means..
i use a class to communicate with database now my test class is working fine.. but when i use my real class it throws a general error same code.
i m puzzled please help
Qasim shabbir.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

post the code, the exception, and tell us which line is throwing the exception. This will keep the guessing to a minimum.
Jamie
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
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 ("qasimshabbir@hotmail.com");
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
Tina Coleman
Ranch Hand

Joined: Dec 12, 2001
Posts: 150
This isn't an immediate answer, unfortunately, but. . . try chaining through your SQLException to see if you can find a more descriptive problem buried in the exception trail. Do something like. . .

I've found that my 'useful' error message was sometimes buried further down the chain, and that I wasn't getting the necessary info to solve the problem until I bounced down through the chain.
Note that the Exception API also has a method getCause(). I've used the before-listed code and haven't used getCause() - just 'cause I hadn't run across it before.
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
thnx 4 yr replies.. i work tht way as u said.. but its not worthy in my case i didnt found any extra information if u'll find thn please tell me.
here is the complete exception stack.
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6135)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:2564)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
at DBConnection.addUser(DBConnection.java:95)
at Server.registerMeToServer(Server.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
Qasim Shabbir
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I see that you have user.getContactNo() but I don't see where you set or initialize contact number?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Exception: General error