Java problem ODBC please help!!

Hi everyone,I am getting an error when i try to compile my java code it says :
SQL Problem: java SQLException: [Microsoft] [ODBC Driver Manager]
function sequense error
I need my code to print out questions and possible answers from my database of questions the code is looping through and printion out the first question and possible answers but then it only prints out the second question and then i get the above error??
Here is my code:
Thanks in advance.
james
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
public class DatabaseConnection
public static void main(String [] arguments)
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
// Load the database drievrs. An ODBC: JDBC bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded");
// Obtain connection to the database.
connection = DriverManager.getConnection("jdbc:odbc:Questions", "", "");
System.out.println("Connection established");
// Cerate statement to read and write to/from database.
statement = connection.createStatement();
System.out.println("Statement created");
//THE PROBLEM STARTS HERE
for (int i = 1; i < 7 ; i++){
rs = statement.executeQuery("SELECT * FROM Questions WHERE [Index] = "+i+" ");
// Get next row.
rs.next();
System.out.println(" ************************************************");
System.out.println("no: " + rs.getString("Index"));
System.out.println("Question : " + rs.getString("Questions"));
System.out.println("Answer A: " + rs.getString("A"));
System.out.println("Answer B: " + rs.getString("B"));
System.out.println("Answer C: " + rs.getString("C"));
rs.next();
// Close statement and conenction.
statement.close();
connection.close();
catch (ClassNotFoundException cnf)
System.out.println("Could not find class: " + cnf);
catch (SQLException sqle)
System.out.println("SQL problem: " + sqle);
//thanks everyone

I think your second next is causing a problem. Assuming there is only one row per index, the second next might generate the error. Try removing the second next. Incidentally, you are getting this error when you run the program not compile it; big difference.

Similar Messages

  • Hello Sorry for the inconvenience, but I have a problem in Java I can not open files, audio chat, which type of jnlp after the last update of the Java 2012-004 Please help me in solving this problem.

    Hello Sorry for the inconvenience, but I have a problem in Java I can not open files, audio chat, which type of jnlp after the last update of the Java 2012-004
    Please help me in solving this problem. 

    Make sure Java is enable in your browser's security settings.
    Open Java Preferences (in Utilities folder)
    Make sure Web-start applications are enabled.
    Drag Java 32-bit to the top of the list.
    jnlp isn't an audio file format. It's just a java web-start program (Java Network Launching Protocol).

  • Counting lines problem. Please help!!

    Hi all,
    I just have a small problem i cannot resolve, here it is: I read through a file and i like to count the lines of the file there is before a special word.
    E.g
    My file contains:
    "hi
    how are you
    my name is john
    and i live
    britain"
    I'd like to count how much lines there are in the file before the word LIVE ==> result would be 4.
    I proceed with StreamTokenizer, but i don't knor how to specify the word. Here is my code:
         try {FileReader fr = new FileReader("test2.dat");
                   BufferedReader br = new BufferedReader(fr);
                   StreamTokenizer stk = new StreamTokenizer(br);
                   do {
                   n = stk.nextToken();
                   li = stk.lineno();
                   if (n == stk.TT_NUMBER) {
                        n = stk.nextToken();
                   if (n == stk.TT_EOL) {
                        li++;
                        n = stk.nextToken();
                   if (n == stk.TT_WORD) {
                        String str = stk.sval;
                        if ("entier".equals(str)) {
                             System.out.println(li);
                        else {
                             n = stk.nextToken();
                   while (??????????????);
    I want here to specify the word "entier" but how to do this??
    Thanks very much for your precious help....

A: Counting lines problem. Please help!!

Use LineNumberReader, which counts lines for you. Here's a complete program in 16 lines:
import java.io.*;
public class test4 {
  public static void main(String[] argv) {
    if (argv.length < 2) { System.err.println("no arg"); System.exit(0); }
    try {
      LineNumberReader in = new LineNumberReader(new FileReader(argv[1]));
      String line;
      while((line = in.readLine()) != null)
        if (line.indexOf(argv[0]) != -1)
          System.out.println("Found match at line " + in.getLineNumber());
    } catch (IOException e) {
      e.printStackTrace();
}If you want case insensitivity, you can make both lines lower-case before searching. Or you can use regular expressions.

Use LineNumberReader, which counts lines for you. Here's a complete program in 16 lines:
import java.io.*;
public class test4 {
  public static void main(String[] argv) {
    if (argv.length < 2) { System.err.println("no arg"); System.exit(0); }
    try {
      LineNumberReader in = new LineNumberReader(new FileReader(argv[1]));
      String line;
      while((line = in.readLine()) != null)
        if (line.indexOf(argv[0]) != -1)
          System.out.println("Found match at line " + in.getLineNumber());
    } catch (IOException e) {
      e.printStackTrace();
}If you want case insensitivity, you can make both lines lower-case before searching. Or you can use regular expressions.

  • Went to open a file in words and got message. "You need a newer version of Pages to open this document." I have latest version.  All other files open w/o a problem.  Please help.

    Went to open a file in words and got message. "You need a newer version of Pages to open this document." I have latest version.  All other files in words open w/o a problem.  Please help.
    Thank you.
    <Email Edited by Host>

    You have 2 versions of Pages on your Mac.
    Pages 5.2 is in your Applications folder.
    Pages '09/'08 is in your Applications/iWork folder.
    You are alternately opening the wrong versions.
    Pages '09/'08 can not open Pages 5 files and you will get the warning that you need a newer version.
    Pages 5.2 can open Pages '09 files but may damage/alter them. It can not open Pages '08 files at all.
    Older versions of Pages 5 can not open files from later versions of Pages 5.
    Once opened and saved in Pages 5 the Pages '09 files can not be opened in Pages '09.
    Anything that is saved to iCloud and opened in a newer version of Pages is also converted to Pages 5 files.
    All Pages files no matter what version and incompatibility have the same extension .pages.
    Pages 5 files are now only compatible with themselves on a very restricted set of hardware, software and Operating Systems and will not transfer correctly on any other server software than iCloud.
    Apple has removed almost 100 features from Pages 5 and added many bugs:
    http://www.freeforum101.com/iworktipsntrick/viewforum.php?f=22&sid=3527487677f0c 6fa05b6297cd00f8eb9&mforum=iworktipsntrick
    Peter

  • Installed successfully but network is not connected. Yet when I go on my Mac network is connected. Is there any other way to solve this problem? Please help.

    Hi,
    I have just installed Windows 7 Home Premium on my Mac book Pro 13inch, it installed successfully but there is no network connection. Yet when I go on my Mac I can get online no problem. Please help or what other way I can do to connect windows online?

    Did you download Windows Support Software when you started installing windows via Bootcamp. If yes you need to then install the Support Software after installing windows which contains Windows drivers for Mac hardware.

  • How come my external hard drive is no longer visible in finder even after ticking it in preferences? it shows in the disk utilities but does not allow me to find a problem or fix the problem? Please help.

    it shows in the disk utilities but does not allow me to find a problem or fix the problem? Please help. also my external hard drive is a seagate free agent go, 500GB. it is visible on my tv but has no files in it… i'm scared i've lost everything?

    Honestly i cannot remember sorry, i got it like 5 maybe 6 yrs ago and just started downloading things to it as the memory on the computer started filling up and when i wanted to see photos/videos on my TV.
    My wife did tell me after i had written this post that she did try and record TV to it as it was plugged in. I think by doing so somehow has deleted everything.   It reads on my TV yet has no files in it but won't show up on my computer. hope this helps.
    Starting to think it is going to cost more to retrieve files on it than it will be to buy a newer and larger one.

  • My new iPhone 5 has black and white lines on the screen. It's not been damaged. I've tried turning it off but this does not solve the problem? Please help.

    My new iPhone 5 has black and white lines on the screen. It's not been damaged. I've tried turning it off but this does not solve the problem? Please help. I can't find my answer on the Internet.

    By far the most common problem hardware-wise seems to be scuffs on the aluminium. Yours is the first report of a faulty screen I've seen.
    If you use the same Apple ID on both devices it'll sync whatever you want it to - music/apps/photos/messages/etc.
    I've just switched from a Galaxy S3 to iPhone 5 (having already owned an iPad for a while) so I'm in a similar position!

  • Adobe Content Viewer problem. Please Help me...

    Hi after updating online. Folio, I tried to update the trial version of the publication on my iPad but I get this message: "the issue isavailable for dowload, but new signing for an application version. Update the application from the App Store. "I went to the AppStore and was not any update of the Content Viewer ... I deleted the version on my iPad I downloaded again ... but without success gives me the same problem ... Please help me ... how can I do??
    thanks

    Hello Bob and thank you for responding so quickly ... Would you be kind enough to send me the link where I can download older versions of Folio Builder and Folio Producers Panel tools for InDesign 5.5. I'm looking for them but I can not find them.
    Thank you for your patience.
    Il giorno 21/gen/2012, alle ore 16:18, Bob Levine ha scritto:
    Re: Adobe Content Viewer problem. Please Help me...
    created by Bob Levine in Digital Publishing Suite - View the full discussion
    As discussed in numerous threads already, the new viewer has not been approved by Apple yet.
    If you’re a pro or enterprise customer you can create your own viewer app. If not, you’ll have to wait or roll back to the older tools.
    Bob
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4155907#4155907
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4155907#4155907. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Digital Publishing Suite by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I kept my iphone on my table so with a half charged battery. I picked it up and it would not turn on then i charged it about an hour but still is not turning on.is it a battery problem? please help!

    i kept my iphone on my table so with a half charged battery. I picked it up and it would not turn on then i charged it about an hour but still is not turning on.is it a battery problem? please help!

    Press and hold both the home and power button until the apple symbol shows up, about 15 seconds.

  • I am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.

    i am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.
    aman

    Are you using Windows...?

  • My IPOD menus suddenly appear in Japanese or Chinese and are impossible to understand for me who is european. Has somebody else had this problem? Please help? The song titles are still in the language they were entered though. /Jane

    My IPOD menus suddenly appear in Japanese or Chinese and are impossible to understand for me who is european. Has somebody else had this problem? Please help? The song titles are still in the language they were entered though. /Jane

    Fingers crossed, the following document might be of some assistance:
    iPod: Changing the display language

  • Tried to access programs and get Error: 16 message. What's the problem? Please help!

    Tried to access programs and get Error: 16 message. What's the problem? Please help! Photoshop, photoshop elements, Dreamweaver - none of my Creative Cloud apps will start-up, since my last update. I need to access these programs for jobs I'm working on.

    Hi wdriver,
    It seems like due to some unknown reason permission from the Licensing folder is removed. Please try launching any of the apps by right clicking and select Run as an Administrator, it should fix the issue by doing that.
    Please let us know if it helps.
    Regards,
    Abhijit

  • Trouble to connect to wireless G routers after installed the latest update 10.10.2  . Anyone with the same problem? Please help Apple support team!! Macbook Pro mid 2010. PS.: Only with wireless G routers, the rest are fine (N, B...)

    Trouble to connect to wireless G routers after installed the latest update 10.10.2  . Anyone with the same problem? Please help !!! Macbook Pro mid 2010. PS.: Only with wireless G routers, the rest are fine (N, B..., and both radio bands)

    Trouble to connect to wireless G routers after installed the latest update 10.10.2  . Anyone with the same problem? Please help !!! Macbook Pro mid 2010. PS.: Only with wireless G routers, the rest are fine (N, B..., and both radio bands)

  • My Ipod doesen't work when I try to connect it on my iTunes! How can I solve this problem? Please help me

    My Ipod doesen't work when I try to connect it on my iTunes! How can I solve this problem? Please help me

    Itunes doesen't see the ipod and it is all dark!

  • Is my iPhone 4 greyed out wifi and non working bluetooth software or hardware... seems that the forums are full of this issue with no consistent or official answer. is it all coincidence that so many are having the problem? Please help...

    Is my iPhone 4 greyed out wifi and non working bluetooth software or hardware... seems that the forums are full of this issue with no consistent or official answer. is it all coincidence that so many are having the problem? Please help... I have scoured the net trying everything the last few days.

    Please correct your porfile: iPhone 4 do not have IOS 6.1.4.
    The usual troubleshooting steps are, also remember to test it after every step:
    1. Restart
    2. Reset
    3. Restore from backup
    4. Restore as new.
    If no joy, make an Appointment with the Apple genius and have them evaluate

  • Maybe you are looking for

    • Dead Ipod photo

      Hello, Since last few days my Ipod Photo is dead. It does not start. Earlier I connected to my Macbook and it started so I formatted and now it does not. When i connect to AC adapter, it still showing "connect to ac supply" icon. I think it is not ab

    • Selective printing restriction in CS4 under Mac OS 10.8 (french edition)

      I run CS4 under Mountain Lion for 2 months without problem .... until yesterday. I can print on my Epson Stylus pro 3800 images with Premium Photo paper (A2 size in the auto sheet feeder ) without problem, but the same image can't be print with Epson

    • File to IDOC scenario using FTP server

      Dear Experts, I'm getting IDOCs in the form of .TXT file from sender side and at reciever end we have IDOC. We are using FTP connection at sender. I want to know: 1. Is FCC the only solution to integrate with PI or do we have any other option also? 2

    • Auto Resize Text in a Text Box

      How do you make the text inside of a text box auto resize to fit the box I'm typing in? I have a text box with a list in it. I change this list everyday and like the text to fit the box. The size of the text doesn't matter. If I have a long list, I d

    • How do I select one page to expire and have another take its place?

      I've gone through the help portion of Contribute and reviewed the expiry pages info but there doesn't seem to be a clear way to expire one page. When I review the manage page expiry window, nothing appears (dialogue box is empty) and I know I'm conne