i have a project which am half way done but on compling ma code it shows errors i need help to clean it

on login it should display a new JFrame with three labels and five buttons with actions
when the book id is entered it should retrive the book(bkbtn) the prvbtn button should take u to the previous book ,nxtbtn next book,lstbtn last book and fstbtn first book but using the book ID LIKE jv001 to move around thanx am in a hurry

import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*; 


class Login extends JFrame implements ActionListener
 {
  JButton SUBMIT;
JButton cancle;
  JPanel panel;
int a;
  JLabel label1,label2;
  final JTextField  text1,text2;
   Login()
   {
   label1 = new JLabel();
   label1.setText("Username:  >>>");
        label1.setFont(new java.awt.Font("Tahoma", 1, 11));
        label1.setForeground(new java.awt.Color(204, 0, 0));
   text1 = new JTextField(15);

   label2 = new JLabel();
   label2.setText("Password:  >>>");
label2.setFont(new java.awt.Font("Tahoma", 1, 11));
        label2.setForeground(new java.awt.Color(204, 0, 0));
   text2 = new JPasswordField(15);
  
   SUBMIT=new JButton("SUBMIT");
   cancle=new JButton("CANCLE");
   panel=new JPanel(new GridLayout(3,1));
   panel.add(label1);
   panel.add(text1);
   panel.add(label2);
   panel.add(text2);
   panel.add(SUBMIT);
panel.add(cancle);
   add(panel,BorderLayout.CENTER);
   SUBMIT.addActionListener(this);
cancle.addActionListener(this);
   setTitle("LOGIN FORM");
pack();
   }
  public void actionPerformed(ActionEvent ae)
   {
if(ae.getSource()==SUBMIT)
{
   String value1=text1.getText();
   String value2=text2.getText();
   if (value1.equals("moses") && value2.equals("momo"))

 {
   book page=new book();
   page.setVisible(true);


text1.setText("");
text2.setText("");
setVisible(false);

   }
   else

{
   //System.out.println("enter the valid username and password");
   JOptionPane.showMessageDialog(this,"Incorrect login or password    Enter the valid username and password","Error",JOptionPane.ERROR_MESSAGE);

text1.setText("");
text2.setText("");
a=2;
   }
}
else
{
System.exit(0);
}

 }

 }
  class LoginDemo
 {
   public static void main(String arg[])
   {
   try
   {

   Login frame=new Login();

   frame.setSize(600,400);
   frame.setVisible(true);
frame.pack();
   


   }
   catch(Exception e)
   {JOptionPane.showMessageDialog(null, e.getMessage());}
   }
 }



import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class book extends JFrame implements ActionListener
{
JTextFeild cd,nm,qt;
JLabel jLabel1,jLabel2,jLabel3,jLabel4;
JButton fstbtn = new JButton();
JButton prvbtn = new JButton();
JButton nxtbtn = new JButton();
JButton lstbtn = new JButton();
Jbutton bkbtn=new JButton();
Container contentPane;
ResultSet rs;
PreparedStatement pst;
String strTemp,strSql,snm,sqt;

int qty;
JPanel panel,panel2;
String password,username,url;
Connection con;

public book()
{

panel=new JPane();
panel.setLayout(new GridLayout(3,2));
panel2=new JPane();
panel2.setLayout(new GridLayout(1,5));
cd=new JTextFeild(20);
nm=new JTextFeild(20);
qt=new JTextFeild(20);

jLabel1=new JLabel();
jLabel2=new JLabel();
jLabel3=new JLabel();
jLabel4=new JLabel();


        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("Book ID");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel2.setForeground(new java.awt.Color(204, 0, 0));
        jLabel2.setText("Book Name");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setForeground(new java.awt.Color(204, 0, 0));
        jLabel3.setText("Books Available");


        fstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        fstbtn.setForeground(new java.awt.Color(255, 0, 0));


        prvbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        prvbtn.setForeground(new java.awt.Color(255, 0, 0));


        nxtbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        nxtbtn.setForeground(new java.awt.Color(255, 0, 0));


        lstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        lstbtn.setForeground(new java.awt.Color(255, 0, 0));


        bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        bkbtn.setForeground(new java.awt.Color(255, 0, 0));
        
        


        fstbtn.setText("l <");

        prvbtn.setText("<<<");

        nxtbtn.setText(">>>");
	
	bkbtn.setText("Books");

        lstbtn.setText("> l");


panel.add(jLabel);
panel.add(cd);
panel.add(jLabe2);
panel.add(nm);
panel.add(jLabe3);
panel.add(qt);
panel2.add(fstbtn);
panel2.add(prvbtn);
panel2.add(bkbtn);
panel2.add(nxtbtn);
panel2.add(lstbtn);

fstbtn.addActionListener(this);

prvbtn.addActionListener(this);

bkbtn.addActionListener(this);

nxtbtn.addActionListener(this);

lstbtn.addActionListener(this);

lstbtn.addActionListener(this);
contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(panel,BorderLayout.PAGE_START);
contentPane.add(panel2,BorderLayout.PAGE_END);

con=this.getConnection();
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);


}
private string getConnection()
{
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:test";
username = "";
password = "";

}
 private Connection getConnection()
{
    
try
{
Class.forName(driver);
con=DriverManager.getConnection(url, username, password);
}
catch(Exception ce)
{
 JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}
}

public void actionPerformed(ActionEvent e)
{
string cat,lbl,cat1,qt1;
cat=cd.getText();
lbl="TAKE BOOK";
int i=1;
if(e.getSource()==bkbtn)

if(bkbtn.getText()=="Books")
{
{
try
{
bkbtn.setText(lbl);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
}
else
{
try
{
qt1=qt.getText();
qt1=qt1-1;
strSql="update books set BooksAvailable="+qt1+" where BkId like "+cat;
JOptionPane.showMessageDialog(this,"");
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}

else if(e.getSource()==prvbtn)
{
try
{
cat1=cat.subString(0,4);
i--;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==fstbtn)
{
try
{
cat1=cat.subString(0,4);
i=1;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==nxtbtn)
{
try
{
cat1=cat.subString(0,4);
i++;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{

strTemp==rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==lstbtn)
{
try
{
cat1=cat.subString(0,4);
i=9;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}


}


}

it shows errors i need help to clean it

Please post the FULL text of your error messages here.

Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Users\Owner>cd desktop

C:\Users\Owner\Desktop>cd libb

C:\Users\Owner\Desktop\libb>javac book.java
book.java:165: ';' expected
whihe(rs.next())
^
book.java:216: ';' expected
whihe(rs.next())
^
book.java:248: ';' expected
whihe(rs.next())
^
book.java:280: ';' expected
whihe(rs.next())
^
book.java:283: not a statement
strTemp==rs.getString("BkName");
^
book.java:312: ';' expected
whihe(rs.next())
^
6 errors

C:\Users\Owner\Desktop\libb>javac LoginDemo.java
.\book.java:165: ';' expected
whihe(rs.next())
^
.\book.java:216: ';' expected
whihe(rs.next())
^
.\book.java:248: ';' expected
whihe(rs.next())
^
.\book.java:280: ';' expected
whihe(rs.next())
^
.\book.java:283: not a statement
strTemp==rs.getString("BkName");
^
.\book.java:312: ';' expected
whihe(rs.next())
^
.\book.java:8: cannot find symbol
symbol : class JTextFeild
location: class book
JTextFeild cd,nm,qt;
^
.\book.java:14: cannot find symbol
symbol : class Jbutton
location: class book
Jbutton bkbtn=new JButton();
^
.\book.java:123: cannot find symbol
symbol : class string
location: class book
private string getConnection()
^
.\book.java:28: cannot find symbol
symbol : class JPane
location: class book
panel=new JPane();
^
.\book.java:30: cannot find symbol
symbol : class JPane
location: class book
panel2=new JPane();
^
.\book.java:32: cannot find symbol
symbol : class JTextFeild
location: class book
cd=new JTextFeild(20);
^
.\book.java:33: cannot find symbol
symbol : class JTextFeild
location: class book
nm=new JTextFeild(20);
^
.\book.java:34: cannot find symbol
symbol : class JTextFeild
location: class book
qt=new JTextFeild(20);
^
.\book.java:88: cannot find symbol
symbol : variable jLabel
location: class book
panel.add(jLabel);
^
.\book.java:90: cannot find symbol
symbol : variable jLabe2
location: class book
panel.add(jLabe2);
^
.\book.java:92: cannot find symbol
symbol : variable jLabe3
location: class book
panel.add(jLabe3);
^
.\book.java:125: cannot find symbol
symbol : variable driver
location: class book
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
^
.\book.java:136: cannot find symbol
symbol : variable driver
location: class book
Class.forName(driver);
^
.\book.java:149: cannot find symbol
symbol : class string
location: class book
string cat,lbl,cat1,qt1;
^
.\book.java:165: cannot find symbol
symbol : method whihe(boolean)
location: class book
whihe(rs.next())
^
.\book.java:169: incompatible types
found : int
required: java.lang.String
sqt=rs.getInt("BooksAvailable");
^
.\book.java:210: operator + cannot be applied to string,int
cat=cat1+i;
^
.\book.java:216: cannot find symbol
symbol : method whihe(boolean)
location: class book
whihe(rs.next())
^
.\book.java:220: incompatible types
found : int
required: java.lang.String
sqt=rs.getInt("BooksAvailable");
^
.\book.java:242: operator + cannot be applied to string,int
cat=cat1+i;
^
.\book.java:248: cannot find symbol
symbol : method whihe(boolean)
location: class book
whihe(rs.next())
^
.\book.java:252: incompatible types
found : int
required: java.lang.String
sqt=rs.getInt("BooksAvailable");
^
.\book.java:274: operator + cannot be applied to string,int
cat=cat1+i;
^
.\book.java:280: cannot find symbol
symbol : method whihe(boolean)
location: class book
whihe(rs.next())
^
.\book.java:284: incompatible types
found : int
required: java.lang.String
sqt=rs.getInt("BooksAvailable");
^
.\book.java:306: operator + cannot be applied to string,int
cat=cat1+i;
^
.\book.java:312: cannot find symbol
symbol : method whihe(boolean)
location: class book
whihe(rs.next())
^
.\book.java:316: incompatible types
found : int
required: java.lang.String
sqt=rs.getInt("BooksAvailable");
^
34 errors

C:\Users\Owner\Desktop\libb>

6 errors if i compile book.java
and 34 if i compile LoginDemo

You have a lot of VERY simple typos and spelling errors that you should correct before wasting time posting this list of errors.

Clean those up and come back with a list of real errors, not just misspellings.

Edited 5 Years Ago by NormR1: n/a

Comments
Agreed.

thanx alot but thats the first step towards helping some one wat u see is not wat i may see thanx alot

Sorry, I don't understand what you are trying to say.
Your code is full of simple misspellings. For example: whihe vs while, string vs String
Correct them, recompile and post the new list of errors.

Edited 5 Years Ago by NormR1: n/a

the errors are gone,it compiled but does not run as expected it trows an eception right before displaying the second JFrame and on clicking ok it displays it.
it also does not display the iformation.
and the bottons are not working properly
thank you alot

import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 


class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JButton cancle;
JPanel panel,panel2;
int a;
JLabel label1,label2;
final JTextField  text1,text2;
JLabel lbhd;
ImageIcon logo,logo1;


Login()
{
label1 = new JLabel();
label1.setText("Username:         >>>");
label1.setFont(new java.awt.Font("Tahoma", 1, 11));
label1.setForeground(new java.awt.Color(204, 0, 0));
text1 = new JTextField(15);
logo=new ImageIcon("C:\\Users\\Owner\\Desktop\\libb\\city.jpg");
Image img = logo.getImage();
Image newimg = img.getScaledInstance(150,80,  java.awt.Image.SCALE_SMOOTH);
logo1 = new ImageIcon(newimg);
lbhd=new JLabel("NEW WAY LIBRALY",logo1,SwingConstants.LEFT);
lbhd.setFont(new java.awt.Font("Algerian", 1, 42));
lbhd.setForeground(new java.awt.Color(0, 0, 255));

label2 = new JLabel();
label2.setText("Password:         >>>");
label2.setFont(new java.awt.Font("Tahoma", 1, 11));
label2.setForeground(new java.awt.Color(204, 0, 0));
text2 = new JPasswordField(15);
  
   SUBMIT=new JButton("SUBMIT");
   cancle=new JButton("CANCLE");
   panel=new JPanel(new GridLayout(3,2));
   panel2=new JPanel(new GridLayout(1,1));
   panel.add(label1);
   panel.add(text1);
   panel.add(label2);
   panel.add(text2);
   panel.add(SUBMIT);
   panel.add(cancle);
   panel2.add(lbhd);
   add(panel,BorderLayout.CENTER);
   add(panel2,BorderLayout.PAGE_START);
   
SUBMIT.addActionListener(this);
cancle.addActionListener(this);
setTitle("LOGIN FORM");
pack();
}
  

public void actionPerformed(ActionEvent ae)
{

if(ae.getSource()==SUBMIT)
{

   String value1=text1.getText();
   String value2=text2.getText();
   if (value1.equals("moses") && value2.equals("momo"))

 {
   book page=new book();
   page.setVisible(true);


   text1.setText("");
   text2.setText("");
   setVisible(false);

}

   
else

{
   
//System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password    Enter the valid username and password","Error",JOptionPane.ERROR_MESSAGE);

text1.setText("");
text2.setText("");
a=2;
   
}

}

else

{


System.exit(0);

}

}

}



class LoginDemo
{
   
public static void main(String arg[])
   
{
   
try
   
{

   
Login frame=new Login();

   
frame.setSize(600,400);
frame.setVisible(true);
frame.pack();
   


   
}
   
catch(Exception e)
   
{
JOptionPane.showMessageDialog(null, e.getMessage());}
   
}

}

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class book extends JFrame implements ActionListener
{
JTextField cd,nm,qt;
JLabel jLabel1,jLabel2,jLabel3,jLabel4;
JButton fstbtn = new JButton();
JButton prvbtn = new JButton();
JButton nxtbtn = new JButton();
JButton lstbtn = new JButton();
JButton bkbtn=new JButton();
Container contentPane;
ResultSet rs;
PreparedStatement pst;
String strTemp,strSql,snm,sqt,driver;

int qty;
JPanel panel,panel2,panel3;
String password,username,url;
Connection con;

JLabel lbhd,lbhd1;
ImageIcon logo,logo1;

public book()
{

panel3=new JPanel(new GridLayout(2,1));
panel=new JPanel();
panel.setLayout(new GridLayout(3,2));
panel2=new JPanel();
panel2.setLayout(new GridLayout(1,5));
cd=new JTextField(30);
nm=new JTextField(30);
qt=new JTextField(20);

jLabel1=new JLabel();
jLabel2=new JLabel();
jLabel3=new JLabel();
jLabel4=new JLabel();

logo=new ImageIcon("C:\\Users\\Owner\\Desktop\\libb\\city.jpg");
Image img = logo.getImage();
Image newimg = img.getScaledInstance(150,80,  java.awt.Image.SCALE_SMOOTH);
logo1 = new ImageIcon(newimg);
lbhd=new JLabel("NEW WAY LIBRALY",logo1,SwingConstants.LEFT);
lbhd.setFont(new java.awt.Font("Algerian", 1, 42));
lbhd.setForeground(new java.awt.Color(0, 0, 255));

lbhd1=new JLabel("NEW WAY LIBRALY for all the books you need !!!!!!!!");
lbhd1.setFont(new java.awt.Font("Algerian", 3, 20));
lbhd1.setForeground(new java.awt.Color(255, 0, 0));


        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Book ID");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel2.setForeground(new java.awt.Color(0, 0, 255));
        jLabel2.setText("Book Name");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setForeground(new java.awt.Color(0, 0, 255));
        jLabel3.setText("Books Available");


        fstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        fstbtn.setForeground(new java.awt.Color(255, 0, 0));


        prvbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        prvbtn.setForeground(new java.awt.Color(255, 0, 0));


        nxtbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        nxtbtn.setForeground(new java.awt.Color(255, 0, 0));


        lstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        lstbtn.setForeground(new java.awt.Color(255, 0, 0));


        bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        bkbtn.setForeground(new java.awt.Color(255, 0, 0));
        
        


        fstbtn.setText("l <");

        prvbtn.setText("<<<");

        nxtbtn.setText(">>>");
	
	bkbtn.setText("Books");

        lstbtn.setText("> l");

panel3.add(lbhd);
panel3.add(lbhd1);
panel.add(jLabel1);
panel.add(cd);
panel.add(jLabel2);
panel.add(nm);
panel.add(jLabel3);
panel.add(qt);
panel2.add(fstbtn);
panel2.add(prvbtn);
panel2.add(bkbtn);
panel2.add(nxtbtn);
panel2.add(lstbtn);

fstbtn.addActionListener(this);

prvbtn.addActionListener(this);

bkbtn.addActionListener(this);

nxtbtn.addActionListener(this);

lstbtn.addActionListener(this);

lstbtn.addActionListener(this);
contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(panel3,BorderLayout.PAGE_START);
contentPane.add(panel,BorderLayout.CENTER);
contentPane.add(panel2,BorderLayout.PAGE_END);

con=this.getConnection();
//setSize(500,200);
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);


}
private String getConnectionUrl()
{
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:test";
username = "";
password = "";

return url;

}
 private Connection getConnection()
{
    
try
{
Class.forName(driver);
con=DriverManager.getConnection(url, username, password);

}
catch(Exception ce)
{
 JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}
return con;
}

public void actionPerformed(ActionEvent e)
{
String cat,lbl,cat1;
cat="";
cat=cd.getText();
lbl="TAKE BOOK";
int i=1,qt1;
if(e.getSource()==bkbtn)

if(bkbtn.getText()=="Books")
{
{
try
{
bkbtn.setText(lbl);
bkbtn.setFont(new java.awt.Font("Tahoma", 1, 14));
bkbtn.setForeground(new java.awt.Color(0, 255, 0));
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
while(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getString("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
}
else
{
try
{
qt1=Integer.parseInt(qt.getText());
qt1=qt1-1;
strSql="update books set BooksAvailable="+qt1+" where BkId like "+cat;
JOptionPane.showMessageDialog(this,"");
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}

else if(e.getSource()==prvbtn)
{
try
{
cat1=cat.substring(0,4);
i--;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
while(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getString("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==fstbtn)
{
try
{
cat1=cat.substring(0,4);
i=1;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
while(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getString("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==nxtbtn)
{
try
{
cat1=cat.substring(0,4);
i++;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
while(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getString("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}
else if(e.getSource()==lstbtn)
{
try
{
cat1=cat.substring(0,4);
i=9;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
while(rs.next())
{

strTemp=rs.getString("BkName");
sqt=rs.getString("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);


}

}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}

}


}


}

it trows an eception

Please copy and paste here the FULL text of the error message. We need that info to help you find the problem.

In every one of your catch blocks you need to print the information about the exception - this shows exactly what went wrong and where (line number).
By not printing this info you do not know anything except that an exception was thrown.
To print the details add the following inside every catch block:
ce.printStackTrace();

Please copy and paste here the FULL text of the error message. We need that info to help you find the problem.

C:\Users\Owner\Desktop\libb>javac LoginDemo.java

C:\Users\Owner\Desktop\libb>java LoginDemo
DataBase Running......!!!!!!
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.reWordAsCountQuery(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.calculateRowCount(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(Unknown Source)
at jav.actionPerformed(jav.java:207)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

i have tried all that i can this is the code

//importing the classes needed

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class jav extends JFrame implements ActionListener
//the class created extends the JFrame class as a supper class and implements the ActionListner
{

//declaring variables (Global variables)
JTextField cd,nm,qt;
JLabel jLabel1,jLabel2,jLabel3,jLabel4;
JButton fstbtn = new JButton();//creating a JButton
JButton prvbtn = new JButton();
JButton nxtbtn = new JButton();
JButton lstbtn = new JButton();
JButton bkbtn=new JButton();
Container contentPane;
ResultSet rs;
PreparedStatement pst;
String strTemp,strSql,snm,sqt,scd,driver;

int qty;
JPanel panel,panel2,panel3;
String password,username,url;
Connection con;

JLabel lbhd,lbhd1;
ImageIcon logo,logo1;

public jav(String s)
//class constructor
{

super(s);

panel3=new JPanel(new GridLayout(2,1));
panel=new JPanel();
panel.setLayout(new GridLayout(3,2));
panel2=new JPanel();
panel2.setLayout(new GridLayout(1,5));
cd=new JTextField(15);
nm=new JTextField(15);
qt=new JTextField(15);

jLabel1=new JLabel();
jLabel2=new JLabel();
jLabel3=new JLabel();
jLabel4=new JLabel();

//creating the logo picture and rescaling 
logo=new ImageIcon("C:\\Users\\Owner\\Desktop\\libb\\city.jpg");
Image img = logo.getImage();
Image newimg = img.getScaledInstance(150,80,  java.awt.Image.SCALE_SMOOTH);
logo1 = new ImageIcon(newimg);
lbhd=new JLabel("NEW WAY LIBRARY",logo1,SwingConstants.LEFT);
//the image is set to the left of the picture

lbhd.setFont(new java.awt.Font("Algerian", 1, 42));
lbhd.setForeground(new java.awt.Color(0, 0, 255));

lbhd1=new JLabel("JAVA BOOKS AVAILABLE     click Rent Book!!!");
lbhd1.setFont(new java.awt.Font("Algerian", 3, 20));
lbhd1.setForeground(new java.awt.Color(255, 0, 0));

//setting text some attributes like colour

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Book ID");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel2.setForeground(new java.awt.Color(0, 0, 255));
        jLabel2.setText("Book Name");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setForeground(new java.awt.Color(0, 0, 255));
        jLabel3.setText("Books Available");


        fstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        fstbtn.setForeground(new java.awt.Color(255, 0, 0));


        prvbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        prvbtn.setForeground(new java.awt.Color(255, 0, 0));


        nxtbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        nxtbtn.setForeground(new java.awt.Color(255, 0, 0));


        lstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        lstbtn.setForeground(new java.awt.Color(255, 0, 0));


        bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
        bkbtn.setForeground(new java.awt.Color(255, 0, 0));
        
        


        fstbtn.setText("l <");

        prvbtn.setText("<<<");

        nxtbtn.setText(">>>");
	
	bkbtn.setText("RENT BOOK");

        lstbtn.setText("> l");

//adding contents to the panels

panel3.add(lbhd);
panel3.add(lbhd1);
panel.add(jLabel1);
panel.add(cd);
panel.add(jLabel2);
panel.add(nm);
panel.add(jLabel3);
panel.add(qt);
panel2.add(fstbtn);
panel2.add(prvbtn);
panel2.add(bkbtn);
panel2.add(nxtbtn);
panel2.add(lstbtn);

//adding action liseners to the buttons

fstbtn.addActionListener(this);

prvbtn.addActionListener(this);

bkbtn.addActionListener(this);

nxtbtn.addActionListener(this);

lstbtn.addActionListener(this);

lstbtn.addActionListener(this);

//adding panels to the content pane

contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(panel3,BorderLayout.PAGE_START);
//setting the layouts of the panels and contentspane

contentPane.add(panel,BorderLayout.CENTER);
contentPane.add(panel2,BorderLayout.PAGE_END);

con=this.getConnection();
pack();
setVisible(true);


}
private String getConnectionUrl()
{
url = "jdbc:odbc:test";
username = "";
password = "";

return url;

}
private Connection getConnection()
{
    
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=java.sql.DriverManager.getConnection(getConnectionUrl(), username, password);
if(con!=null)
System.out.println("DataBase Running......!!!!!!");

}
catch(Exception ce)
{
 JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);


}
return con;
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bkbtn)
{
if(bkbtn.getText()=="RENT BOOK")
{
try
{
bkbtn.setText("TAKE BOOK");
bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
bkbtn.setForeground(new java.awt.Color(0, 0, 255));

strSql="select*from java where BookID like ?";

pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

pst.setString(1,"Jv001");
rs=pst.executeQuery();
while(rs.next())
{
strTemp=rs.getString("BookName");
scd=rs.getString("BookID");
int sq=rs.getInt("BooksAvailable");
cd.setText(scd);
nm.setText(strTemp);
qt.setText(""+sqt);
}


}
catch(Exception ce)

{

 JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
 ce.printStackTrace();

}

}
else if(bkbtn.getText()=="TAKE BOOK")
{

bkbtn.setText("RENT BOOK");
bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
bkbtn.setForeground(new java.awt.Color(255, 0, 0));

Done dn=new Done("thanx...");

}

}
else if(e.getSource()==fstbtn)
{



}
else if(e.getSource()==lstbtn)
{



}
else if(e.getSource()==prvbtn)
{



}
else if(e.getSource()==nxtbtn)
{



}



}


}

i need the program to display the book name ID and books left from the database when some clicks rent book thank you
I am running out of time

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(Unknown Source)
at jav.actionPerformed(jav.java:207)

It looks like you are doing something at line 207 that is causing the above error.

This article has been dead for over six months. Start a new discussion instead.