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

    Default Error: illegal start of expression

    Hai i am develop program which are connected to database. For database i am using mAccess .In my program i am try to insert data. For you info the connection to database is ok . I think may be my code having a probleam. I need you advice ..here is my code and i also highlight which line cause this error.Please correct my code ...

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

    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 /*here is the line which give me error*/
    {
    ActInsertData obj = new ActInsertData();
    obj.getConnection();
    obj.insertData();
    }
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Error: illegal start of expression

    For future reference, please wrap your code within the code tags...it makes it actually readable by a human.

    Check for brackets...for example, the line immediately above the main method where your error occurs should be within a method itself. If you are not sure what this means, I refer you to the following: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

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

    Default Re: Error: illegal start of expression

    "For you info the connection to database is ok"
    Not sure how you know that since the above code doesn't compile does it?

Similar Threads

  1. Error: "Illegal start of expression"
    By mokitooo_1994 in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 09:42 PM
  2. Another Illegal Start of Expression
    By miss_peaches in forum New To Java
    Replies: 2
    Last Post: 05-11-2011, 04:41 PM
  3. Illegal start of expression error pls help me!
    By Gayethiri_86 in forum New To Java
    Replies: 12
    Last Post: 05-12-2010, 03:06 PM
  4. Illegal start of expression error
    By lukermsdn111 in forum New To Java
    Replies: 9
    Last Post: 03-22-2010, 01:31 PM
  5. Servlet Error -illegal start of expression
    By raghu9198 in forum Java Servlet
    Replies: 2
    Last Post: 04-21-2009, 11:12 PM

Posting Permissions

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