I am new to programming and am trying to create a program to access a database of DVD's. I want to input a unique code for a title and display relevant fields from that record.
I am getting the error above and have spent many hours now trying to see where I am going wrong.

The code:

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

public class TEST1
{
    public static void main( String args[] )
    {

        String inputDVDcode;
        String indata;       
        getdetails calldvd;

        indata=JOptionPane.showInputDialog("Enter a DVD Code or (-1 to quit): ");   //call dialogue box requesting dvd code
        inputDVDcode = (indata);                                     //assign dvd code to inputDVDcode variable;

        getdetails();

    //  System.out.println(inputDVDcode);   //test if input works
    }

    public static void getdetails(String args[])                               //gets dvd details and displays in JoptionPane
        {
            Connection connection;
            Statement st;
            String out="";
            JTextArea display=new JTextArea();

            try
                {
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    connection= DriverManager.getConnection("jdbc:odbc:MYDVDS","","");
                    st = connection.createStatement();
                    ResultSet rec = st.executeQuery( "SELECT Cost, Title, Genre, Category FROM finaldetails where Code = 'inputDVDcode' "); 

                    while (rec.next()) 
                        { 
                            out="DVD : " + rec.getString("Title")+"\t"+ rec.getString("Genre")+"\t"+ rec.getString("Category") + "\t"+ rec.getString("Cost");
                            display.setText(out);
                            JOptionPane.showMessageDialog(null,display);
                        }
                }
                    catch (Exception e) 
                        {
                            e.printStackTrace();
                            System.exit(0); 
                        }
        }

}

I get the error:

getdetails(java.lang.String[]) in TEST1 cannot be applied to ()

Can anyone please at least point me in the right direction?

Cheers

Edited 3 Years Ago by Nick Evan: Fixed formatting

Hello,

Firstly, Please post your code inside the [ CODE ] [ / CODE] tag.

There are many problems with your code and you really need to do hard work on it.

Its not a big deal to solve your programming mistakes but the thing that matters is, you will be able to understand those changes or not ?

So i suggest you to understand these topics first:

Defining Methods : http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html

String Concatenation : http://www.java-samples.com/showtutorial.php?tutorialid=217

Best of luck!

Thank you for your reply. I will read some more and let you know how it goes.

Thank you for your reply. I will read some more and let you know how it goes.

Hi you code shold be like as follows

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

public class TEST1
{
public static void main( String args[] )
{

String inputDVDcode;
String indata;
//getdetails calldvd; you cannot create reference for the methods in java.

indata=JOptionPane.showInputDialog("Enter a DVD Code or (-1 to quit): "); //call dialogue box requesting dvd code
inputDVDcode = (indata); //assign dvd code to inputDVDcode variable;

getdetails();

// System.out.println(inputDVDcode); //test if input works
}

public static void getdetails() // remove the Arguments from the signature
{
Connection connection;
Statement st;
String out="";
JTextArea display=new JTextArea();

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection= DriverManager.getConnection("jdbc:odbc:MYDVDS","","");
st = connection.createStatement();
ResultSet rec = st.executeQuery( "SELECT Cost, Title, Genre, Category FROM finaldetails where Code = 'inputDVDcode' ");

while (rec.next())
{
out="DVD : " + rec.getString("Title")+"\t"+ rec.getString("Genre")+"\t"+ rec.getString("Category") + "\t"+ rec.getString("Cost");
display.setText(out);
JOptionPane.showMessageDialog(null,display);
}
}
catch (Exception e)
{
e.printStackTrace();
System.exit(0);
}
}

}

Thank you for your time in replying to my question.

Having done a lot of reading and research around this problem, it seems as if I am trying to run before I can walk but I would really like to solve this none the less.

When I use the above code, the program just hangs after I give it an input value. There is no JOptionpane displaying the result of the query.

Any ideas what is causing this?

First send me the exception what you are getting,
and try to analyze the following code this might help you

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

import utils.system;

public class TEST1 {
	public static void main(String args[]) {
		String DVDId;
		String DVDInfo = null;
		JTextArea display = new JTextArea();
		DVDId = JOptionPane
				.showInputDialog("Enter a DVD Code or (-1 to quit): ");
		
		DVDInfo = getdetails(DVDId); 
//call the getdetails method with given DVDId ,it will return you the info
		
		display.setText(DVDInfo);
		JOptionPane.showMessageDialog(null, display);
	}

	public static String getdetails(String dvdId) //get details from Database
	{
		String returnInfo = null;
		Connection connection;
		Statement st;
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			connection = DriverManager
					.getConnection("jdbc:odbc:MYDVDS", "", "");
			st = connection.createStatement();
			ResultSet rec = st
					.executeQuery("SELECT Cost, Title, Genre, Category FROM finaldetails where Code = '"+dvdId+"' ");

			while (rec.next()) {
				returnInfo = "DVD : " + rec.getString("Title") + "\t"
						+ rec.getString("Genre") + "\t"
						+ rec.getString("Category") + "\t"
						+ rec.getString("Cost");
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		if(returnInfo==null){
			returnInfo="No Results Found";
		}
		return returnInfo;
	}

}

Don't forget to close the ResultSet, the Statement, and the Connection.
Also instead of while you could use an 'if'.
If more than one row is expected, use 'while', but like this:

returnInfo = "";
while (rec.next()) {
				returnInfo += "DVD : " + rec.getString("Title") + "\t"
						+ rec.getString("Genre") + "\t"
						+ rec.getString("Category") + "\t"
						+ rec.getString("Cost") + "\n";
			}
if(returnInfo.equals("")){
	returnInfo="No Results Found";
}

Brilliant. Thank you for your replies, I have solved the problem and learned some in getting there.

This question has already been answered. Start a new discussion instead.