Errorjava.sql.SQLException - General Error... HELP!!!

We are using JDK1.5.. MS access db. Eclipse IDE. The program has no problem retrieving data... but it gets stuck when we use executeUpdate... Showing the above error statement.

import java.sql.*;

import javax.swing.*;

import java.io.*;

public class db

{

public static void main(String args[])

{

int i,size=0,CID=0,type=0;

String lang=" ",str2,str3;

String userinput="abc";

ResultSet res1,res,res2;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn = DriverManager.getConnection("jdbc:odbc:DatasourceDSN");

Statement stat = conn.createStatement();

Statement stat1=conn.createStatement();

Statement stat2=conn.createStatement();

String str = "Select * from ContentProfile where Location='"+userinput+"'";

res = stat.executeQuery(str);

while(res.next())

{

size=res.getInt("Size");

lang=res.getString("Language");

CID=res.getInt("ContentId");

type=res.getInt("Type");

System.out.println(size+lang+CID);

}

str2="select ClientId,DeviceId,ClientProfile.Language as cl,ClientProfile.Type as ct,Size from ClientProfile,DeviceProfile where ClientProfile.Language=DeviceProfile.Language";

res1=stat1.executeQuery(str2);

while(res1.next())

{

int cid=res1.getInt("ClientId");

int did=res1.getInt("DeviceId");

String lan =res1.getString("cl");

int typ=res1.getInt("ct");

int siz=res1.getInt("Size");

System.out.println(cid+did+lan+typ+siz);

}

str3="Insert into SourceProfile values("+CID+","+size+",'"+lang+"',"+type+")";

i = stat2.executeUpdate(str3);

if(i!=0)

{

System.out.println("inserted into Source profile"+i);

}

}

catch(Exception e)

{

System.out.println("Error" +e);

}

}

}

We have no idea what the error means!!! We tried using a finally block... but no use.Please help.. someone...!!!!!

[2030 byte] By [supremaa] at [2007-11-26 15:21:22]
# 1
> We have no idea what the error means!!! We tried> using a finally block... but no use.ROFL.Anyway. Start using PreparedStatements.
cotton.ma at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
try to close you ms access
jgalacambraa at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Please elaborate the problem..Mentions the errors or exceptions in details. use exception.printStackTrace() method in the catch block and paste those exceptions here...
ali_hammada at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Small Suggestions:1. While passing arguements to a query, use PreparedStatement.2. Instead of the simple System.out.println(Exception), use e.printStackTrace();
JintoKLa at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

hi ,

i did try to use the prepareStatement... but still the same eroor occurs and the errors..are as follows..

java.sql.SQLException: General error

at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)

at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)

at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)

at database.main(database.java:48)

this is the changed part of the code...

PreparedStatement stat2=conn.prepareStatement("Insert into SourceProfile values(?,?,?,?)");

stat2.setInt(1,CID);

stat2.setInt(2,size);

stat2.setString(3,lang);

stat2.setInt(4,type);

stat2.executeUpdate();

wht is the problem...? i did try closing my MS access .. when i executed the code.....

supremaa at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

"General error" -- it's well known that Microsoft spends millions of dollars to ensure the usability and user-friendliness of its products. Money well spent.

Anyway, that basically means you are doing things in the wrong order. In this case you're trying to update the database through a connection while you are still reading from the same connection. Closing the result sets before trying to write to the database might help. And even if it doesn't you should still be closing your result sets after you're finished reading from them.

DrClapa at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
thank you clap.. i got the code working ... i dont know wht made the difference but .. tried running every part of the code seperately and got it working together .
supremaa at 2007-7-8 21:36:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...