Results 1 to 2 of 2
  1. #1
    iswan is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Error: reached end of file while parsing

    hai , i am developed a program with database connection. In my code i am try to insert data. For database connection is no probleam but i have probleam with my code which i got an error reached end of file parsing . Please correct my code please cause i can identify what is the probleam is. I also highlight line which give me this error..

    import javax.swing.JOptionPane;
    import java.sql.*;

    XML Code:
     public class ActInsertData {
    
        String userid="saya", password="1234";
    	String url="jdbc:odbc:Semester2";
    		Statement stmt;
    		Connection con;
     
        public void getConnection()
    {
    try
    	{
    	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    	}
    catch(java.lang.ClassNotFoundException e)
    	{
     	System.err.print("classNotFoundException:");
    	System.err.println(e.getMessage());
    	}
    try
    	{
    	 con=DriverManager.getConnection(url,userid, password);
    	if(con!= null)
    	{
     
    	System.out.println("Got Connection.");
    	DatabaseMetaData meta=con.getMetaData();
    	System.out.println("Driver Name: " + meta.getDriverName());
    	}
    else
     System.out.println("Could not Get Connection");
    	}
    	catch(SQLException ex)
    	{
    	
    	System.err.println("SQLException: " +ex.getMessage());
    	}
    }
    public void insertData()
    {
     
     String insertString1 = "insert into student values('ALI', 15, 'MALE' )";
    String  insertString2 = "insert into student values('AHMAD', 16, 'MALE')";
    String insertString3 = "insert into student values('AYU, 15,'FEMALE')";
    String insertString4 = "insert into student values('ANI', 17,'FEMALE')";
    
    try
    {
    stmt = con.createStatement();
    stmt.executeUpdate(insertString1);
    stmt.executeUpdate(insertString2);
    stmt.executeUpdate(insertString3);
    stmt.executeUpdate(insertString4);
    stmt.close();
    con.close();
    }
    catch(SQLException ex)
     {
    System.err.println("SQLException: " + ex.getMessage());
    }
    
    System.out.println("Data Inserted into Student Table");
    
    public static void main(String[] args) throws Exception/* this is the line which cause an error*/
    {
    ActInsertData obj = new ActInsertData();
    obj.getConnection();
    obj.insertData();
    }
    }
    Last edited by iswan; 09-28-2011 at 09:01 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,854
    Rep Power
    19

    Default Re: Error: reached end of file while parsing

    You need to write your code with proper indentation.
    Your naming is fine (which is a rarity here), but you need to line everything correctly otherwise it's almost impossible to follow the flow...and really hard to match up brackets.
    eg
    Java Code:
    public class MyClass {
        private int someAttribute;
    
        public void someMethod() {
            if (someAttribute > 0) {
                doSomething();
            }
        }
    
        private void doSomething() {
        }
    }
    Sort that out then you'll see what your problem is.

Similar Threads

  1. reached end of file while parsing- using bluej
    By prendergast36 in forum New To Java
    Replies: 1
    Last Post: 09-08-2011, 09:00 PM
  2. FTP parsing remote file error
    By agangaia in forum New To Java
    Replies: 0
    Last Post: 04-18-2011, 08:45 PM
  3. Replies: 1
    Last Post: 05-31-2009, 06:48 PM
  4. intimating file(s) have reached/copied in directory
    By ashu261 in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 06:24 PM
  5. signaling file(s) have reached in directory
    By ashu261 in forum Advanced Java
    Replies: 0
    Last Post: 02-04-2008, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •