Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with ExecuteUpdate

843854Mar 7 2005 — edited Mar 8 2005
Hi All, im having a problem with this JAVA update, was wondering if you guys could help me....

Heres the code, byt the way im using net beans and am using a JDBC-ODBC bridge in the runtime tab

heres the code and out put thanks again Nick


// Test Class
public class Test {

public static void main(String[] args) {
UserDAO dao = new UserDAO();

try {
UserVO user = new UserVO();
user.setUserID("Alan");
dao.insert(user);
user.setEmail("alan@agparkinson.co.uk");
dao.update(user);
//System.out.println(obj);
} catch (DataAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}


// Insert
public void insert(ValueObjects object) throws DataAccessException {
Connection con;
Statement state;
ResultSet rs;

UserVO user = null;
if (object instanceof UserVO) {
user = (UserVO) object;
String insertStatement = "INSERT INTO tblUser (userID, firstName, surName, password, town, email) VALUES ('"
+ user.getUserID() + "', '" + user.getFirstName() + "', '" + user.getSurName() + "', '" + user.getPassword() + "', '" + user.getTown() + "', '" + user.getEmail() + "')";

// access database
try {
Class.forName(DBLocation.DRIVER);
con = DriverManager.getConnection(DBLocation.URL, "", "");
state = con.createStatement();
state.executeUpdate(insertStatement);
//rs = state.executeQuery("SELECT * FROM tblUser WHERE
// userID='" + key +"'");

//rs.close();
state.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage());
}//try
}
}


Output Below

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 sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
at src.uk.ac.uwe.dbay.dao.access.UserDAO.insert(UserDAO.java:106)
at src.test.Test.main(Test.java:28)
src.uk.ac.uwe.dbay.dao.DataAccessException: General error
at src.uk.ac.uwe.dbay.dao.access.UserDAO.insert(UserDAO.java:115)
at src.test.Test.main(Test.java:28)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2005
Added on Mar 7 2005
4 comments
662 views