Results 1 to 2 of 2
- 09-28-2011, 08:58 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
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.
- 09-28-2011, 09:33 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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
Sort that out then you'll see what your problem is.Java Code:public class MyClass { private int someAttribute; public void someMethod() { if (someAttribute > 0) { doSomething(); } } private void doSomething() { } }
Similar Threads
-
reached end of file while parsing- using bluej
By prendergast36 in forum New To JavaReplies: 1Last Post: 09-08-2011, 09:00 PM -
FTP parsing remote file error
By agangaia in forum New To JavaReplies: 0Last Post: 04-18-2011, 08:45 PM -
E:\IT 215 Java Programming\Inventory.java:211: reached end of file while parsing
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 06:48 PM -
intimating file(s) have reached/copied in directory
By ashu261 in forum Threads and SynchronizationReplies: 1Last Post: 04-23-2008, 06:24 PM -
signaling file(s) have reached in directory
By ashu261 in forum Advanced JavaReplies: 0Last Post: 02-04-2008, 07:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks