Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class JdbcConnection {
  4.  
  5. public static void main(String args[]) {
  6.  
  7. Connection con = null;
  8.  
  9. String url = "jdbc:mysql://vikingsec1.db.5837770.hostedresource.com";
  10. String db = "vikingsec1";
  11. String driver = "com.mysql.jdbc.Driver";
  12. String user = "vikingsec1";
  13. String pass = "BisBeta1963";
  14.  
  15. try {
  16. Class.forName(driver);
  17.  
  18. con = DriverManager.getConnection(url + "/" + db, user, pass);
  19. System.out.println("test2");
  20. System.out.println("jdbc driver for mysql : " + driver);
  21. System.out.println("test3");
  22.  
  23. System.out.println("Connection url : " + url + db);
  24. System.out.println("Connection is created...");
  25.  
  26. // declare object of Statement interface that uses for executing sql statements.
  27. Statement statement = null;
  28.  
  29. // declare a resultset that uses as a table for output data from the table.
  30. ResultSet rs = null;
  31. int updateQuery = 0;
  32.  
  33. /* createStatement() is used for create
  34. statement object that is used for sending sql
  35. statements to the specified database. */
  36. statement = con.createStatement();
  37.  
  38. // sql query of string type to create a data base.
  39. //String QueryString = "CREATE TABLE values(temp INTEGER , trip INTEGER)";
  40. //updateQuery = statement.executeUpdate(QueryString);
  41.  
  42.  
  43. // sql query to insert values in the specified table.
  44. String query = "UPDATE 'values' SET 'temp'=1 WHERE 'temp'=0 AND 'trip'=0 LIMIT 1";
  45. updateQuery = statement.executeUpdate(query);
  46.  
  47. if (updateQuery != 0) {
  48. System.out.println("table is created successfully and " + updateQuery + " row is inserted.");
  49. }
  50.  
  51.  
  52. con.close();
  53. System.out.println("Connection is closed...");
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. System.out.println(e);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement