Abdullah047

PerparedStatement_SQL

Sep 2nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package sqltest;
  7.  
  8. import java.sql.DriverManager;
  9. import java.sql.*;
  10. /**
  11.  *
  12.  * @author Abdullah
  13.  */
  14. public class PreparedStatements {
  15.     public static void main(String[] args) throws SQLException{
  16.         String URL="jdbc:mysql://localhost:3306/hawk?autoReconnect&useSSL=false";
  17.         String User="root";
  18.         String Password="abdullah";
  19.             int  ID=1;
  20.             String SQL=
  21.     "SELECT * FROM table1 WHERE ID=?"
  22.                 ;
  23.            
  24.         Connection connect=DriverManager.getConnection(URL, User, Password);
  25.         PreparedStatement PS=connect.prepareStatement(SQL);
  26.         PS.setInt(1, ID);
  27.         ResultSet Result= PS.executeQuery();
  28.      while(Result.next()){
  29.              System.out.println(Result.getString(1)+"\t"+Result.getString(2) );
  30.    
  31.      
  32.      
  33.      }
  34.    
  35.    
  36.    
  37.    
  38.     }
  39. }
Add Comment
Please, Sign In to add comment