Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java SQL Exception General Error

 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just trying to learn the Java.sql class as well as odbcs, the following is my code, I have everything spelled correctly and all the cases match up, I will post my code below and the printStackTrace from the error as well
package quote;
import java.sql.*;
/**
*
* @author tech
*/
public class Connect {
public static void main(String[] args)
{
try {
String dataSourceName = "mdbTEST";
String dbURL = "jdbcdbc:" + dataSourceName;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "","");
Statement s = con.createStatement();
s.execute("INSERT INTO TEST12345 VALUES('1','2')"); // Line 25
s.close(); // close the Statement to let the database know we're done with it
con.close();
}
catch (Exception e) {
System.out.println("Error: " + e);
e.printStackTrace();
}
}

/** Creates a new instance of Connect */
public Connect() {
}

}

error is the following:
java.sql.SQLException: General error

at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6987)

at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)

at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)

at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)

at quote.Connect.main(Connect.java:25)\\where my error is

Any help would be greatly appreciated, I am using DSNs.
 
Manhar Puri
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesse,

Your code looks fine to me, just check if your insert statement works from the sql editor i.e. try your insert directly on the database.

Also just check if you are actually able to get the connection successfully.

-Manhar.
[ March 29, 2007: Message edited by: Manhar Puri ]
 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the java.sql package part of the JRE or does it have to have a SDK installed on the computer?
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're developing Java applications, you'll need the SDK. JRE would suffice for end users. What database are you using? Try updating your driver name to that of the library you're using.
 
Ratan Kumar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database you are using?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic