Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1.  
  2. /**
  3. * Created by gqdw on 9/28/16.
  4. */
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.sql.ResultSet;
  10.  
  11. public class MyTest {
  12.  
  13. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  14. static final String DB_URL = "jdbc:mysql://xxx.27.199.225/myzb";
  15.  
  16. static final String USER = "";
  17. static final String PASS = "";
  18.  
  19.  
  20. public static void main(String[] args) {
  21. Connection conn = null;
  22. Statement stmt = null;
  23. try{
  24. Class.forName("com.mysql.jdbc.Driver1");
  25. System.out.println("connecting to database...");
  26. conn = DriverManager.getConnection(DB_URL,USER,PASS);
  27.  
  28. stmt = conn.createStatement();
  29. String sql0;
  30. sql0 = "select eventid,clock from events limit 10";
  31. ResultSet rs = stmt.executeQuery(sql0);
  32.  
  33. while(rs.next()){
  34. Integer eventid = rs.getInt("eventid");
  35. Integer clock = rs.getInt("clock");
  36. System.out.println("eventid: " + eventid + "\t" + "clock:" + clock);
  37. }
  38. rs.close();
  39. stmt.close();
  40. conn.close();
  41. }catch(ClassNotFoundException ce){
  42. System.out.println("Class not found.");
  43. ce.printStackTrace();
  44. System.exit(1);
  45. }
  46. catch(SQLException se){
  47. se.printStackTrace();
  48. }catch(Exception e){
  49. e.printStackTrace();
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement