Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. +------------+--------------+------+-----+---------+-------+
  2. | Field | Type | Null | Key | Default | Extra |
  3. +------------+--------------+------+-----+---------+-------+
  4. | PERSON_ID | int(8) | NO | PRI | NULL | |
  5. | LAST_NAME | varchar(256) | NO | | NULL | |
  6. | FIRST_NAME | varchar(256) | NO | | NULL | |
  7. | STREET | varchar(256) | NO | | NULL | |
  8. | CITY | varchar(256) | NO | | NULL | |
  9. +------------+--------------+------+-----+---------+-------+
  10.  
  11. Smith,John,Old Street 99,London
  12. Rossi, Antonio, P.zza Croce 17, Roma
  13.  
  14. public class MysqlCon {
  15.  
  16. public static void main(String args[]) {
  17.  
  18. Scanner input;
  19.  
  20. String line = "";
  21. String cvsSplitBy = ",";
  22.  
  23. try {
  24. Class.forName("com.mysql.jdbc.Driver");
  25. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Test?useSSL=false", "root",
  26. "db09");
  27. // here sono is database name, root is username and password
  28. java.sql.Statement stmt = con.createStatement();
  29.  
  30. try {
  31. FileReader fileReader = new FileReader("/Users/Simone/Documents/workspace/DBDemo/src/Person.data");
  32. input = new Scanner(fileReader);
  33. BufferedReader reader = new BufferedReader(fileReader);
  34.  
  35. while ((line = reader.readLine()) != null) {
  36. System.out.println(line);
  37.  
  38. // use comma as separator
  39. String[] country = line.split(cvsSplitBy);
  40. System.out.println(country[0]);
  41.  
  42. }
  43. reader.close();
  44.  
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. System.exit(1);
  48. }
  49. con.close();
  50. } catch (Exception e) {
  51. System.out.println(e);
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement