Guest User

Untitled

a guest
Mar 2nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class MysqlConnect{
  4. public static void main(String[] args) {
  5. System.out.println("MySQL Connect Example.");
  6. Connection conn = null;
  7. String url = "jdbc:mysql://localhost:3306/";
  8. String dbName = "stock1";
  9. String driver = "com.mysql.jdbc.Driver";
  10. String userName = "root";
  11. String password = "alaaelamin";
  12. ResultSet r ;
  13. Statement s = null;
  14. try {
  15. Class.forName(driver).newInstance();
  16. conn = DriverManager.getConnection(url+dbName,userName,password);
  17.  
  18. System.out.println("Connected to the database");
  19.  
  20. r = s.executeQuery("alaaelamin");
  21.  
  22. while (r.next()) {
  23. String y = r.getString("name");
  24. String x = r.getString("age");
  25. String z = r.getString("car");
  26. Statement stmt = conn.createStatement(
  27. ResultSet.TYPE_SCROLL_INSENSITIVE,
  28. ResultSet.CONCUR_READ_ONLY);
  29. ResultSet rs;
  30. System.out.println(y);
  31. System.out.println(x);
  32. }
  33.  
  34. conn.close();
  35. System.out.println("Disconnected from database");
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment