Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java database error
- 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 ) ;
- }
- }
- }
- UPDATE people SET id = 9842 WHERE birthyear=3434
Add Comment
Please, Sign In to add comment