db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Ambrose <glennambr...@hotmail.com>
Subject importing
Date Mon, 11 Jan 2010 12:24:17 GMT


I have been having some trouble trying to import data from a csv file.
The program opens a JFileChooser where a .csv file can be selected and entered under the variable
'dataSource'. Importing is achieved (not working) with CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE

public class Database {
    public void go() throws ClassNotFoundException, SQLException{
        //Get connection to database
        String url = "jdbc:derby://localhost:1527/DerbyElements";
        Connection connect = DriverManager.getConnection(url, "root", "enter");
        //Create an object to hold a SQL statement
        Statement carrier = connect.createStatement();
        //Select file with the JFileChooser
        //Create an object 'fileChooser' that represents the data source
        JFileChooser fileChooser = new JFileChooser();
        //Create variable 'dataSource' to hold the file url
        String dataSource = "";
        int openFile = fileChooser.showOpenDialog(fileChooser);
        //Check if a file has been choosen
        if(openFile == JFileChooser.APPROVE_OPTION){
            File file = fileChooser.getSelectedFile();
            //Make dataSource the path to the file
            dataSource = file.getAbsolutePath();
            //Load data from the file
            "CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (null,'elements',"+dataSource+",null,null,null,0)"
      //  carrier.execute("delete from elements where atomicnumber=2");

At the end, commented out I tried just issuing SQL commands, carrier.execute("delete from
elements where atomicnumber=2"); and these work fine.

The csv file contains:

2,"Helium","He",1,18,"Noble gas",4.0026
3,"Lithium","Li",2,1,"Alkali metal",6.941
4,"Beryllium","Be",2,2,"Alkaline earth metal",9.01218
10,"Neon","Ne",2,18,"Noble gas",20.1797

The error I get is:

Exception in thread "main" java.sql.SQLSyntaxErrorException: Syntax error: Encountered "/"
at line 1, column 53.
        at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
        at org.apache.derby.client.am.Statement.execute(Unknown Source)
        at csv2derby.Database.go(Database.java:36)
        at csv2derby.Main.main(Main.java:21)
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "/" at line
1, column 53.
        at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.readPrepare(Unknown Source)
        at org.apache.derby.client.net.StatementReply.readPrepare(Unknown Source)
        at org.apache.derby.client.net.NetStatement.readPrepare_(Unknown Source)
        at org.apache.derby.client.am.Statement.readPrepare(Unknown Source)
        at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
        at org.apache.derby.client.am.Statement.executeX(Unknown Source)
        ... 3 more
Java Result: 1

Any help would be greatly appreciated 


Shopping Trolley Mechanic If It Exists, You'll Find it on SEEK
View raw message