Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sqltest;
- import java.sql.DriverManager;
- import java.sql.*;
- /**
- *
- * @author Abdullah
- */
- public class PreparedStatements {
- public static void main(String[] args) throws SQLException{
- String URL="jdbc:mysql://localhost:3306/hawk?autoReconnect&useSSL=false";
- String User="root";
- String Password="abdullah";
- int ID=1;
- String SQL=
- "SELECT * FROM table1 WHERE ID=?"
- ;
- Connection connect=DriverManager.getConnection(URL, User, Password);
- PreparedStatement PS=connect.prepareStatement(SQL);
- PS.setInt(1, ID);
- ResultSet Result= PS.executeQuery();
- while(Result.next()){
- System.out.println(Result.getString(1)+"\t"+Result.getString(2) );
- }
- }
- }
Add Comment
Please, Sign In to add comment