Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Scanner;
- public class appli{
- public static void main(String args[]){
- try{
- //step1 load the driver class
- Class.forName("oracle.jdbc.OracleDriver");
- //step2 create the connection object
- Connection con=DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:XE","ETUDIANT","ETUDIANT");
- //step3 create the statement object
- Statement stmt=con.createStatement();
- //step4 execute query
- //question 1
- ResultSet rs1=stmt.executeQuery("select * from avion");
- while(rs1.next())
- System.out.println(rs1.getInt(1)+" "+rs1.getString(2)+" "+rs1.getString(3));
- //question 2
- String s;
- Scanner sc1 = new Scanner(System.in);
- System.out.println("Entrez nom de la ville : ");
- s = sc1.nextLine();
- String request2;
- request2 =" select * from avion where Entrepot = '" + s + "'";
- ResultSet rs2=stmt.executeQuery(request2);
- while(rs2.next())
- System.out.println(rs2.getInt(1)+" ");
- //question 3
- PreparedStatement rs3=con.prepareStatement("select * from avion where Entrepot = ?");
- Scanner sc2 = new Scanner(System.in);
- System.out.println("Entrez nom de la ville : ");
- s = sc2.nextLine();
- rs3.setString(1,s);//1 specifies the first parameter in the query .
- rs3.executeUpdate();
- //step5 close the connection object
- con.close();
- }catch(Exception e){ System.out.println(e);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement