Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Main {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost/gistda_db";
- // Database credentials
- static final String USER = "root";
- static final String PASS = "wiriya11403";
- public static void main(String[] args){
- Connection conn = null;
- Statement stmt = null;
- try{
- //STEP 2: Register JDBC driver
- Class.forName(JDBC_DRIVER);
- //STEP 3: Open a connection
- System.out.println("Connecting to database...");
- conn = DriverManager.getConnection(DB_URL,USER,PASS);
- System.out.println("Creating statement...");
- stmt = conn.createStatement();
- String sql = "SELECT id FROM optemis_job ORDER BY id DESC limit 1";
- ResultSet rs = stmt.executeQuery(sql);
- int job_id = 0;
- while(rs.next()){
- job_id = rs.getInt("id");
- }
- rs.close();
- sql = "UPDATE optemis_job SET percent = 10 WHERE id=" + job_id;
- stmt.executeUpdate(sql);
- Thread.sleep(2000);
- sql = "UPDATE optemis_job SET percent = 30 WHERE id=" + job_id;
- stmt.executeUpdate(sql);
- Thread.sleep(2000);
- sql = "UPDATE optemis_job SET percent = 50 WHERE id=" + job_id;
- stmt.executeUpdate(sql);
- Thread.sleep(2000);
- sql = "UPDATE optemis_job SET percent = 70 WHERE id=" + job_id;
- stmt.executeUpdate(sql);
- Thread.sleep(2000);
- sql = "UPDATE optemis_job SET percent = 100 WHERE id=" + job_id;
- stmt.executeUpdate(sql);
- stmt.close();
- conn.close();
- }catch(SQLException se){
- //Handle errors for JDBC
- se.printStackTrace();
- }catch(Exception e){
- //Handle errors for Class.forName
- e.printStackTrace();
- }finally{
- //finally block used to close resources
- try{
- if(stmt!=null)
- stmt.close();
- }catch(SQLException se2){
- }// nothing we can do
- try{
- if(conn!=null)
- conn.close();
- }catch(SQLException se){
- se.printStackTrace();
- }//end finally try
- }//end try
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement