0

I already parsed the csv file in java. Now I should insert the file into a database. I used the mysql workbench and created some tables. Now it seams that I made a mistake in the line where I tried to insert the data. I think the DB Commection works.

Can anyone find a mistake in my code?
Ill also include the error message.


package medInfo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectDB {
    
    private Connection conn;
    Statement upd;
    PreparedStatement pstmt;
    
    
    public ConnectDB() {
    
        System.out.println("Start...");
        try {
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logfile", "root", "");
            
        }catch (ClassNotFoundException | SQLException e) {
            System.err.println(e.getMessage());
        }
    }


    public void insertMetadata(Metadaten m) {
        try {
            pstmt = conn.prepareStatement("INSERT IGNORE INTO metadaten (guid, gender, agegroup, town) VALUES('"
                    +m.getGuid()+"','"+m.getGender()+"','"+m.getAgegroup()+"','"+m.getTown()+"')");                 
            pstmt.executeUpdate();
        }catch (SQLException e) {
            e.printStackTrace();
        }
        
    }

}


Error:
com.mysql.jdbc.Driver
Exception in thread "main" java.lang.NullPointerException
    at medInfo.ConnectDB.insertMetadata(ConnectDB.java:31)
    at medInfo.Importer.main(Importer.java:17)


Thanks!
kikivhb
  • 11

0 Answers0