problem in finding the data
while i am finding the data the field of TelephoneNo
showing the result in float like 54435435.0.even when i inserted this phone no as 54435435 my code is
String findby =cbfind.getSelectedItem().toString();
if(findby.equals("")){
JOptionPane.showMessageDialog(null," SELECT EITHER REGISTRATION NO OR NAME");
return;
}
if(findby.equals("RegNo"))
{
int regno1= Integer.parseInt(cbregn.getSelectedItem().toString());
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("\n Driver loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM REGISTRATION1 WHERE RegistrationNo="+regno1);
System.out.println("Hi");
rs.next();
String per = rs.getString("SeniorPerson");
System.out.println("SeniorPerson: " + per );
String reg = rs.getString("RegistrationNo");
System.out.println("RegistrationNo: " + reg);
String nplace = rs.getString("NativePlace");
System.out.println("NativePlace: " + nplace);
String kul = rs.getString("Kul");
System.out.println("Kul: " + kul);
String gtr = rs.getString("Gotra");
System.out.println("Gotra: " + gtr);
String ksami = rs.getString("KulSwami");
System.out.println("KulSwami: " + ksami);
String raddr = rs.getString("ResidensialAddress");
System.out.println("ResidensialAddress: " + raddr);
String code = rs.getString("PinCode");
System.out.println("PinCode: " + code);
String stdcd = rs.getString("STDcode");
System.out.println("STDcode: " + stdcd);
String teleno = rs.getString("TelephoneNo");
System.out.println("TelephoneNo: " + teleno);
String mno = rs.getString("MobileNo");
System.out.println("MobileNo: " + mno);
String email = rs.getString("Email");
System.out.println("Email: " + email);
String web = rs.getString("Website");
System.out.println("Website: " + web);
String educ = rs.getString("Education");
System.out.println("Education: " + educ);
String brch = rs.getString("Branch");
System.out.println("Branch: " + brch);
String bgrp = rs.getString("BloodGroup");
System.out.println("BloodGroup: " + bgrp);
JOptionPane.showMessageDialog(null, "RECORD FOUND");
cbnm.setSelectedItem(per);
tfplace.setText(nplace);
tfkul.setText(kul);
tfgotra.setText(gtr);
tfswami.setText(ksami);
taraddr.setText(raddr);
tfpcd.setText(code);
tfstdcode.setText(stdcd);
tftele.setText(teleno);
tfmno.setText(mno);
tfemail.setText(email);
tfweb.setText(web);
tfedu.setText(educ);
tfbrch.setText(brch);
cbbldgrp.setSelectedItem(bgrp);
}
catch (Exception e)
{
System.out.println("EXCEPTION " + e);
}
}
if(findby.equals("Name"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("\n Driver loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM REGISTRATION1 WHERE SeniorPerson='"+cbnm.getSelectedItem().toString()+"'");
System.out.println("Hi");
rs.next();
String per = rs.getString("SeniorPerson");
System.out.println("SeniorPerson: " + per );
String reg = rs.getString("RegistrationNo");
System.out.println("RegistrationNo: " + reg);
String nplace = rs.getString("NativePlace");
System.out.println("NativePlace: " + nplace);
String kul = rs.getString("Kul");
System.out.println("Kul: " + kul);
String gtr = rs.getString("Gotra");
System.out.println("Gotra: " + gtr);
String ksami = rs.getString("KulSwami");
System.out.println("KulSwami: " + ksami);
String raddr = rs.getString("ResidensialAddress");
System.out.println("ResidensialAddress: " + raddr);
String code = rs.getString("PinCode");
System.out.println("PinCode: " + code);
String stdcd = rs.getString("STDcode");
System.out.println("STDcode: " + stdcd);
String teleno = rs.getString("TelephoneNo");
System.out.println("TelephoneNo: " + teleno);
String mno = rs.getString("MobileNo");
System.out.println("MobileNo: " + mno);
String email = rs.getString("Email");
System.out.println("Email: " + email);
String web = rs.getString("Website");
System.out.println("Website: " + web);
String educ = rs.getString("Education");
开发者_如何学Go System.out.println("Education: " + educ);
String brch = rs.getString("Branch");
System.out.println("Branch: " + brch);
String bgrp = rs.getString("BloodGroup");
System.out.println("BloodGroup: " + bgrp);
JOptionPane.showMessageDialog(null, "RECORD FOUND");
cbregn.setSelectedItem(reg);
tfplace.setText(nplace);
tfkul.setText(kul);
tfgotra.setText(gtr);
tfswami.setText(ksami);
taraddr.setText(raddr);
tfpcd.setText(code);
tfstdcode.setText(stdcd);
tftele.setText(teleno);
tfmno.setText(mno);
tfemail.setText(email);
tfweb.setText(web);
tfedu.setText(educ);
tfbrch.setText(brch);
cbbldgrp.setSelectedItem(bgrp);
}
catch (Exception e)
{
System.out.println("EXCEPTION " + e);
}
}//if
I'm going to wager that it's because that's how it's stored in the DB.
Use varchar
rather than whatever it is you're using.
The answer you are seeing is most likely due to:
defining the column type for the telephone number to be "float", "double", "decimal", "numeric" or "real", or
defining the column type as "char", "varchar", etc and populating it from a Java
float
,double
orBigDecimal
.
In either case, what you are seeing reflects the data stored in the database.
精彩评论