Results 1 to 4 of 4
  1. #1
    mistajokka is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Annoying syntax error in Eclipse!!

    Hey everyone, I am trying to code an Android app that uses JDBC to Sybase and everything has went smooth with the code until the very last closing right bracket that says "Syntax error on token "}", delete this token".

    Here is my code:

    package com.jconnecttest;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    import android.app.Activity;
    import android.os.Bundle;

    public class JConnectTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try {
    Class.forName("com.sybase.jdbc.SybDriver");
    }catch(ClassNotFoundException e){
    System.err.println("Error loading driver: " + e);}
    String host = "my.sybase.serverurl";
    String dbName = "mydatabasename";
    int port = 2638;
    String sybaseURL = "jdbc:sybase:Tds:" + host +
    ":" + port + ":" + "?SERVICENAME=" + dbName;
    String username = "dba";
    String password = "mydbapassword";
    Connection connection =
    DriverManager.getConnection(sybaseURL, username, password);
    Statement statement = connection.createStatement();
    String query = "SELECT name, address, phone FROM company";
    ResultSet resultSet = statement.executeQuery(query);
    while(resultSet.next()){
    System.out.println(resultSet.getString(1) + " " +
    resultSet.getString(2) + " " +
    resultSet.getString(3));
    connection.close();
    }
    }
    }
    } <--------- THIS is the one it is giving the error on...I even tried creating a new project and re typing all the code clean but it keeps giving me this!!

    Please help :(

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: Annoying syntax error in Eclipse!!

    Do as Eclipse told you to do, you have one right curly bracket too many.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mistajokka is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Annoying syntax error in Eclipse!!

    If I do that, my code above it starts to have errors:

    Annoying syntax error in Eclipse!!-6807818003_2112fddb39_b.jpg

    A bunch of "Unhandled exception type SQLException"...it goes away if I add that extra bracket...weird

  4. #4
    vivekanand30 is offline *****
    Join Date
    Sep 2011
    Location
    Mumbai
    Posts
    8
    Rep Power
    0

    Default Re: Annoying syntax error in Eclipse!!

    That's the very basic thing which you can't see as the error itself says that "Unhandled exception type SQLException" it means you need to surround it with try catch block. You should know there are some exception which you have to handle in your code this is what happening in your case. For your reference look at the below code


    Java Code:
    package com.example.android.notepad;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class test extends Activity {
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		///setContentView(R.layout.main);
    		try {
    			Class.forName("com.sybase.jdbc.SybDriver");
    		}catch(ClassNotFoundException e){
    			System.err.println("Error loading driver: " + e);}
    		String host = "my.sybase.serverurl";
    		String dbName = "mydatabasename";
    		int port = 2638;
    		String sybaseURL = "jdbc:sybase:Tds:" + host +
    				":" + port + ":" + "?SERVICENAME=" + dbName;
    		String username = "dba";
    		String password = "mydbapassword";
    		Connection connection;
    		try {
    			connection = DriverManager.getConnection(sybaseURL, username, password);
    		
    		Statement statement = connection.createStatement();
    		String query = "SELECT name, address, phone FROM company";
    		ResultSet resultSet = statement.executeQuery(query);
    		while(resultSet.next()){
    			System.out.println(resultSet.getString(1) + " " +
    					resultSet.getString(2) + " " +
    					resultSet.getString(3));
    			connection.close();
    		}
    		
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    }
    Please read the throw, throws and try catch block. URL

Similar Threads

  1. Very annoying error for array assignment
    By DudeJericho in forum New To Java
    Replies: 2
    Last Post: 04-20-2011, 02:07 PM
  2. Syntax error in eclipse for "enum" defination.
    By gunwantw in forum Eclipse
    Replies: 1
    Last Post: 07-08-2010, 09:21 AM
  3. Syntax in eclipse
    By insectincest in forum Eclipse
    Replies: 1
    Last Post: 04-12-2010, 11:10 AM
  4. Annoying problem class/interface error
    By Chick786 in forum New To Java
    Replies: 2
    Last Post: 04-11-2010, 04:36 PM
  5. Insanely annoying java error...
    By Nukleahboy in forum New To Java
    Replies: 10
    Last Post: 08-07-2009, 09:22 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
  •