Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. package Reviseknowledge;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.util.ArrayList;
  7.  
  8. public class Learn {
  9.  
  10. public static void main(String[] args) throws Exception {
  11.  
  12.  
  13. }
  14.  
  15.  
  16. static String url = "jdbc:mysql://localhost:3306/guest";
  17. static String username = "root";
  18. static String password = "guest123";
  19.  
  20.  
  21.  
  22.  
  23.  
  24. public static void update () throws Exception {
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /*
  47. public static void createTable () throws Exception {
  48.  
  49. try {
  50.  
  51. Connection conn = DriverManager.getConnection(url,username,password);
  52.  
  53. PreparedStatement create = conn.prepareStatement("CREATE TABLE IF NOT EXISTS stebuklas "
  54. + "( first varchar(253), "
  55. + "last varchar(250),"
  56. + "numbers integer(50) )");
  57. create.executeUpdate();
  58.  
  59. }
  60.  
  61. catch(Exception e){ System.out.println(e); }
  62.  
  63. finally { System.out.println ("table was madee"); }
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. public static void post () throws Exception {
  75.  
  76. String var1 = "ann";
  77. String var2 = "lesh";
  78. double var3 = 5;
  79.  
  80. try {
  81. Connection conn = DriverManager.getConnection(url,username,password);
  82. PreparedStatement posted = conn.prepareStatement (" INSERT INTO stebuklas "
  83. + "(first,last,numbers) VALUES ('"+var1+"', '"+var2+"', '"+var3+"')");
  84.  
  85. posted.executeUpdate ();
  86. posted.executeUpdate ();
  87.  
  88. }
  89. catch(Exception e){ System.out.println(e); }
  90.  
  91. finally {System.out.println ("values inserted to the table.");}
  92.  
  93.  
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100. public static void get() throws Exception {
  101. try{
  102. Connection conn = DriverManager.getConnection(url,username,password);
  103. PreparedStatement statement = conn.prepareStatement("SELECT * FROM stebuklas LIMIT 2");
  104. PreparedStatement stat = conn.prepareStatement("SELECT * FROM stebuklas LIMIT 3");
  105.  
  106. ResultSet result = statement.executeQuery ();
  107. ResultSet res = stat.executeQuery ();
  108.  
  109. while (result.next() ) {
  110.  
  111. System.out.println ( result.getString("first") );
  112.  
  113. }
  114.  
  115.  
  116. while ( res.next() ) {
  117.  
  118. System.out.println ( res.getInt("numbers") );
  119.  
  120. }
  121.  
  122.  
  123. }
  124. catch(Exception e){ System.out.println(e); }
  125.  
  126.  
  127.  
  128. }
  129.  
  130. */
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement