Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +------------+--------------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +------------+--------------+------+-----+---------+-------+
- | PERSON_ID | int(8) | NO | PRI | NULL | |
- | LAST_NAME | varchar(256) | NO | | NULL | |
- | FIRST_NAME | varchar(256) | NO | | NULL | |
- | STREET | varchar(256) | NO | | NULL | |
- | CITY | varchar(256) | NO | | NULL | |
- +------------+--------------+------+-----+---------+-------+
- Smith,John,Old Street 99,London
- Rossi, Antonio, P.zza Croce 17, Roma
- public class MysqlCon {
- public static void main(String args[]) {
- Scanner input;
- String line = "";
- String cvsSplitBy = ",";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Test?useSSL=false", "root",
- "db09");
- // here sono is database name, root is username and password
- java.sql.Statement stmt = con.createStatement();
- try {
- FileReader fileReader = new FileReader("/Users/Simone/Documents/workspace/DBDemo/src/Person.data");
- input = new Scanner(fileReader);
- BufferedReader reader = new BufferedReader(fileReader);
- while ((line = reader.readLine()) != null) {
- System.out.println(line);
- // use comma as separator
- String[] country = line.split(cvsSplitBy);
- System.out.println(country[0]);
- }
- reader.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- con.close();
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement