Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package javaapplication1;
  2.  
  3. import java.sql.*;
  4. import java.io.*;
  5.  
  6.  
  7.  
  8. public class prepare {
  9.  
  10. public static void main(String args[]) throws Exception
  11. {
  12.  
  13.  
  14. try{
  15.  
  16. Class.forName("com.mysql.jdbc.Driver");
  17. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/idemi?zeroDateTimeBehavior=convertToNull","root","");
  18. System.out.println("Connection created.. !");
  19. PreparedStatement ps = conn.prepareStatement("insert into boy values(?,?)");
  20.  
  21.  
  22.  
  23. boolean b = ps.execute("create table boy(name varchar(30), age int)");
  24. System.out.println("Table Boy created... !");
  25. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  26.  
  27. System.out.println("Enter boy name");
  28. String bname = br.readLine();
  29.  
  30. System.out.println("Enter boy age");
  31. int bage = Integer.parseInt(br.readLine());
  32.  
  33. ps.clearParameters();
  34.  
  35. ps.setString(1,bname);
  36. ps.setInt(2, bage);
  37.  
  38. ps.executeUpdate();
  39. }
  40. catch(Exception e)
  41. {
  42. System.out.println(e);
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement