Error in Insert into statement...

From: dan dan via JavaKB.com (forum_at_JavaKB.com)
Date: 03/14/05

  • Next message: Silvio Bierman: "Re: JDBC and ResultSet problem"
    Date: Mon, 14 Mar 2005 08:15:04 GMT
    
    

    Below is my Java Program..there's no error when compiling but i cannot run
    this file..

    It stop executing when it reach the INSERT INTO statement.. Anybody knows
    what's wrong?

    import java.io.*;
    import java.util.*;
    import java.sql.*;

    public class E
    {
            final static String TABLE_NAME = "CpGIsland";
            final static String inputFileName = "test.txt";

            public static int NUM =50; // Number of input lines

            public static String [][] input = new String[NUM][100];
            public static int count_input =0; // count for input file

            public static int dataIndex = 0;
            public static String DELIM = ",";

            public static Statement s;
            public static Connection con=null;
            public static ResultSet rs;

            public E()
            {

            }

            public static void DropTable()throws Exception
            {
            try {
                                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                    /* the next 3 lines are Step 2 method 2 from above - you could use the
    direct
                                    access method (Step 2 method 1) istead if you wanted */
                                    String dataSourceName = "mdbTEST";
                                    String dbURL = "jdbc:odbc:" + dataSourceName;
                                Connection con = DriverManager.getConnection(dbURL, "","");

                                    s = con.createStatement();

                          System.out.print(" Dropping Table: " + TABLE_NAME + "\n");
                        s.execute("DROP TABLE " + TABLE_NAME);

                        System.out.print(" - Dropped Table...\n");

                        System.out.print(" Closing Statement...\n");
                        s.close();

                           }
                            catch (SQLException e)
                                    {
                                e.printStackTrace();
                                    }
            }

            public static void CreateTable()throws Exception
            {

             try
              {
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    /* the next 3 lines are Step 2 method 2 from above - you could use the
    direct
                    access method (Step 2 method 1) istead if you wanted */
                    String dataSourceName = "mdbTest1";
                    String dbURL = "jdbc:odbc:" + dataSourceName;
                       Connection con = DriverManager.getConnection(dbURL, "","");

                    s = con.createStatement();

                    System.out.print(" Creating Table: " + TABLE_NAME + "\n");

                    s.execute("CREATE TABLE " + TABLE_NAME + " (" +
                    " Name String " +
                    " , Location String " +
                    " , Size String " +
                    " , Sum String " +
                    " , Percent String " +
                    " , ObsExp String " +
                    " , NoOfIsland String )");

                    System.out.print(" - Created Table...\n");

              }

                catch (SQLException e)
                    {
                      e.printStackTrace();
                    }

         }

            public static void readWriteFile() throws SQLException
            {

            int insertResults = 0;

            StringTokenizer st = null;

            String n;
            String lctn;
            String sz;
            String sm;
            String p;
            String oe;
            String no;

            try {

                System.out.print(" Creating Statement...\n");

                System.out.print(" Create FileReader Object for file: " +
    inputFileName + "...\n");
                FileReader inputFileReader = new FileReader(inputFileName);

                System.out.print(" Create BufferedReader Object for FileReader
    Object...\n");
                BufferedReader inputStream = new BufferedReader
    (inputFileReader);

                String inLine = null;
                while ((inLine = inputStream.readLine()) != null) {

                st = new StringTokenizer(inLine, DELIM);

                n = st.nextToken();
                lctn = st.nextToken();
                sz = st.nextToken();
                sm = st.nextToken();
                p = st.nextToken();
                oe = st.nextToken();
                no = st.nextToken();

                System.out.print(" Inserting value for [" + n + "]\n");

                s.executeUpdate( "INSERT INTO "
                + TABLE_NAME + " VALUES (" +
                " , '" + n + "'" +
                " , '" + lctn + "'" +
                " , '" + sz + "'" +
                " , " + sm +
                " , '" + p + "'" +
                " , " + oe +
                " , '" + no + "')");

              System.out.print(" " + insertResults + " row created.\n");
                }

                System.out.print(" Commiting Transaction...\n");
                con.commit();

                System.out.print(" Closing inputString...\n");
                inputStream.close();

                System.out.print(" Closing Statement...\n");
                s.close();

            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            }

    public static void main(String[] args)
    {

            E runExample = new E();

            try {
                    runExample.DropTable();
                    runExample.CreateTable();
                    runExample.readWriteFile();
                    }

                catch(Exception e)
                {
                  System.err.println("trouble.......");
                       e.printStackTrace();
                   return;
                }
            }//ends void main

    }//ends class E

    -- 
    Message posted via http://www.javakb.com
    

  • Next message: Silvio Bierman: "Re: JDBC and ResultSet problem"

    Relevant Pages

    • Assembly References - User Compiled
      ... I am compiling a class with the CSharpCodeProvider, ... namespace MySpace { ... public class ProcessingClass { ... //Get MyClass Instance ...
      (microsoft.public.dotnet.framework)
    • Re: Putting a Form on a new thread
      ... The problem is that after StartForm finishes executing, ... dies. ... > public class FormStarter ...
      (microsoft.public.dotnet.framework.windowsforms)
    • Re: Simple Java Problem
      ... Fix by setting the classpath, ... putting the referring and the referred to ... "public class Foo" is defined in a file named "foo.java" ... Fix by compiling the class. ...
      (comp.lang.java.help)
    • Re: Newbie question regarding packages
      ... He's responding to the OP's question, which I'm requoting here for the benefit of other readers who may have missed that post. ... I am going through a java for dummies book and have an issue compiling ... public class PackageTest ...
      (comp.lang.java.help)
    • Newbie question regarding packages
      ... I am going through a java for dummies book and have an issue compiling ... public class PackageTest ...
      (comp.lang.java.help)