Я использую следующий код для обновления записи в моей базе данных.Ошибка базы данных 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
Пожалуйста, покажите свое определение таблицы. –