9 Replies - 175 Views - Last Post: 05 December 2017 - 08:40 AM Rate Topic: -----

#1 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

first record not showing up from the database

Posted 05 December 2017 - 07:32 AM

hi all

i need a quick answer. I have an assignment to finished where I have to use a next and previous button but before add any codes to my actual program, I have created a dummy programt to practice the previous and next jbutton just to see how it should be working. I want it to be able to call the first record, then go to the next record when the next button click or to go back to the previous record when the previous button is click. i build the program with a database, i entered just one record and run it to see if it will show up in the gui just to make sure that it is working properly but the problem is when I run the program nothing is showing in the gui. so I am wondering what is in my codes that is causing it not to be shown. here is the codes that I used.

the codes below is just the first part, I haven't reached the previous or next button as yet. it supposed to show the first record.

package Employess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

public class Workers extends javax.swing.JFrame {

    Connection conn;
    Statement stmt;
    ResultSet rs;
    
  
    
    public Workers() {
        initComponents();
        DoConnect();
    }
      public void DoConnect(){
          
          //connection to the database
          try{
              String host  =  "jdbc: derby://localhost:3306/employees";
              String uName = "admin";
              String uPass = "admin";
              conn = DriverManager.getConnection(host, uName, uPass);
              
              //execute some sql and load the records into the result set
              stmt = conn.createStatement();
              String sql ="SELECT * FROM  workers";
              rs = stmt.executeQuery(sql);
              
              //move the cursor the first record and get the data
              rs.next();
              int id_col = rs.getInt("ID");
              String id = Integer.toString(id_col);
              String first = rs.getString("firstname");
              String last = rs.getString("lastname");
              String job = rs.getString("jobtitle");
              
              //display the first record in the text field
              textID.setText(id);
              textFirstName.setText(first);
              textLastName.setText(last);
              textJobTitle.setText(job);              
          }
          catch(SQLException err){
              JOptionPane.showMessageDialog(Workers.this, err.getMessage());
          }
          
        
    }



Is This A Good Question/Topic? 0
  • +

Replies To: first record not showing up from the database

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14091
  • View blog
  • Posts: 56,456
  • Joined: 12-June 08

Re: first record not showing up from the database

Posted 05 December 2017 - 07:38 AM

It's been some time since I rode the Java train, but wouldn't "ResultSet" be a collection of results from the database? Zero to many sort of thing? If that's the case I would think you should be able to use an index, like an array, to get the first result from the ResultSet object.

(or use any of the other functions to do that too)
https://docs.oracle..../ResultSet.html

.. like first!
https://docs.oracle....tml#first%28%29
Was This Post Helpful? 1
  • +
  • -

#3 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • Joined: 20-September 08

Re: first record not showing up from the database

Posted 05 December 2017 - 08:17 AM

That cannot be the code you're running, as it would not compile. Please post your actual code or it just wastes everyone's time
Was This Post Helpful? 1
  • +
  • -

#4 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

Re: first record not showing up from the database

Posted 05 December 2017 - 08:18 AM

hey #2 modi123_1

what I 4get 2 mention is that when I run the program a joptionpane dialog box pop up and say that there is no suitable driver found for jdbc database_form//localhost: 3306/employess
Was This Post Helpful? 0
  • +
  • -

#5 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • Joined: 20-September 08

Re: first record not showing up from the database

Posted 05 December 2017 - 08:20 AM

You need to put the Derby driver jar in the classpath
Was This Post Helpful? 0
  • +
  • -

#6 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

Re: first record not showing up from the database

Posted 05 December 2017 - 08:21 AM

goose what codes do you think it is?

that is the codes, that I am running, it is just the beginning not the whole entire codes, I am just testing as time goes with every block of codes I write, I am testing to see if it is working, I am sure that u does do that always and if you think that I am wasting other pple time then I am sorry for wasting yours.

apparently goose, like u didnt read my introduction. what I said before I post the code
Was This Post Helpful? -1
  • +
  • -

#7 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

Re: first record not showing up from the database

Posted 05 December 2017 - 08:26 AM

hey goose

is the derby driver jar a bin.zip or a tar.zip
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • Joined: 20-September 08

Re: first record not showing up from the database

Posted 05 December 2017 - 08:32 AM

Quote

apparently goose, like u didnt read my introduction. what I said before I post the code

I most certainly did. You might think it helps to post edited versions of your code, but it doesn't.

Quote

is the derby driver jar a bin.zip or a tar.zip

I'm not sure what you mean by that. The driver is a jar file. You might find that it comes packaged in a zip. Read the docs
Was This Post Helpful? 1
  • +
  • -

#9 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

Re: first record not showing up from the database

Posted 05 December 2017 - 08:34 AM

I am not going to argue here but thanks anyways
Was This Post Helpful? 0
  • +
  • -

#10 divinity28   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 21-December 14

Re: first record not showing up from the database

Posted 05 December 2017 - 08:40 AM

hey

I got it to work, it just i had entered some errors in the db
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1