我正在使用以下代码更新数据库中的记录。Java数据库错误
import java.sql.* ;
class JDBCUpdate
{
public static void main(String args[])
{
String DB_URL = "jdbc:mysql://localhost/mydatabase";
try
{
Class.forName("com.mysql.jdbc.Driver") ;
// Database credentials
String USER = "user";
String PASS = "pass";
// Get a connection to the database
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
// Print all warnings
for(SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning())
{
System.out.println("SQL Warning:") ;
System.out.println("State : " + warn.getSQLState() ) ;
System.out.println("Message: " + warn.getMessage() ) ;
System.out.println("Error : " + warn.getErrorCode()) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the Update
int rows = stmt.executeUpdate("UPDATE people SET id = 9842 WHERE birthyear=3434") ;
// Print how many rows were modified
System.out.println(rows + " Rows modified") ;
// Close the statement and the connection
stmt.close() ;
conn.close() ;
}
catch(SQLException se)
{
System.out.println("SQL Exception:") ;
// Loop through the SQL Exceptions
while(se != null)
{
System.out.println("State : " + se.getSQLState() ) ;
System.out.println("Message: " + se.getMessage() ) ;
System.out.println("Error : " + se.getErrorCode()) ;
se = se.getNextException() ;
}
}
catch(Exception e)
{
System.out.println(e) ;
}
}
}
在stmt.executeUpdate(),如果我尝试更新的文字或大于整数抛出错误以外的任何值的记录。有人能告诉我如何克服这个错误。
_what_错误被抛出? – cdeszaq 2012-03-13 14:48:58
请显示您的表格定义。 – 2012-03-13 14:55:27