Example : How to increase serial number automatically taking data from oracle 10g database.
import static javax.swing.JOptionPane.*;
public registration()
{
initComponents(); //Load event in Java
void autoslno()
{
try
{
Integer x=0;
Integer y=0;
String q="select SLNO from BOOKDETAILS";
pst=conn.prepareStatement(q);
rs=pst.executeQuery();
while (rs.next())
{
String cmbid=rs.getString("SLNO");
cmbid.trim();
x=Integer.parseInt(cmbid);
if(y<x)
{
y=x;
}
y=y+1;
String cmbid1=Integer.toString(y); //convert integer to string
jTextFieldSLNO.setText(cmbid1);
}
System.out.print(x);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
}
}
--------- OR ----------
public registration()
{
initComponents();
Integer x=0;
Integer y=0;
try
{
String sql = "select REGSLNO from REGISTRATION";
pst = conn.prepareStatement(sql);
rs=pst.executeQuery();
while(rs.next())
{
x= Integer.parseInt(rs.getString("REGSLNO"));
//showMessageDialog(null,x);
if(y<x)
{
y=x;
}
y=y+1;
jTxtRegSlno.setText(Integer.toString(y));
}
}
catch(Exception e)
{
out.println(e);
}
}
0 Comments