Results 1 to 4 of 4
- 02-02-2012, 05:18 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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 :(
- 02-02-2012, 05:25 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Annoying syntax error in Eclipse!!
Do as Eclipse told you to do, you have one right curly bracket too many.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-02-2012, 07:22 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
- 02-02-2012, 07:53 PM #4
*****
- Join Date
- Sep 2011
- Location
- Mumbai
- Posts
- 8
- Rep Power
- 0
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
Please read the throw, throws and try catch block. URLJava 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(); } } }
Similar Threads
-
Very annoying error for array assignment
By DudeJericho in forum New To JavaReplies: 2Last Post: 04-20-2011, 02:07 PM -
Syntax error in eclipse for "enum" defination.
By gunwantw in forum EclipseReplies: 1Last Post: 07-08-2010, 09:21 AM -
Syntax in eclipse
By insectincest in forum EclipseReplies: 1Last Post: 04-12-2010, 11:10 AM -
Annoying problem class/interface error
By Chick786 in forum New To JavaReplies: 2Last Post: 04-11-2010, 04:36 PM -
Insanely annoying java error...
By Nukleahboy in forum New To JavaReplies: 10Last Post: 08-07-2009, 09:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks