SQL
구문에 오류가 있습니다 . 사용중인 MySQL
서버 버전에 해당하는 설명서 itid=1
에서 1 행 근처 에서 사용할 올바른 구문을 확인하십시오.
결제 애플리케이션에 대한 청구서를 생성하려고 할 때 위의 오류가 표시됩니다. 다음은 내 응용 프로그램의 코드입니다. 이 오류를 해결할 수있는 몇 가지 해결책을 알려주세요. 미리 감사드립니다.
public void actionPerformed(ActionEvent ae)
{
String str1=(String)ae.getActionCommand();
Object source = ae.getSource();
if(source==home)
{
this.dispose();
home t=new home();
t.nn("","","","");
}
if(source==add)
{
name.setEditable(false);
pho.setEditable(false);
da.setEditable(false);
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/billing", "root", "");
Statement stm = c.createStatement();
t=0;
if(pho.getText().length()!=10&&pho.getText().length()!=0)
jp.showMessageDialog(this,"Phone Number Must Have 10 Digits","INFORMATION",jp.ERROR_MESSAGE);
else
{
ResultSet rs1 = stm.executeQuery("select * from bill where billid="+bid.getText()+"and itid="+id.getText());
while(rs1.next())
{
t=1;
}
if(t==0)
{
t=0;
PreparedStatement ps = c.prepareStatement("insert into bill values(?,?,?,?,?,?)");
if((bid.getText()).length()!=0)
ps.setString(1,bid.getText());
else
ps.setString(1,"");
if((name.getText()).length()!=0)
ps.setString(2,name.getText());
else
ps.setString(2,"");
if((pho.getText()).length()!=0)
ps.setString(3,pho.getText());
else
ps.setString(3,"");
if((da.getText()).length()!=0)
ps.setString(4,da.getText());
else
ps.setString(4,"");
if((id.getText()).length()!=0)
ps.setString(5,id.getText());
else
ps.setString(5,"");
if((co.getText()).length()!=0)
ps.setString(6,co.getText());
else
ps.setString(6,"");
ps.executeUpdate();
//jp.showMessageDialog(this,"Record Inserted Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
it[cu]=Integer.parseInt(id.getText());
coun[cu++]=Integer.parseInt(co.getText());
}
else
{
jp.showMessageDialog(this,"Sorry, Item ID is Already Entered","INFORMATION",jp.ERROR_MESSAGE);
t=0;
}
}
c.close();
stm.close();
}
catch(ClassNotFoundException cnf)
{
System.out.println("Cnf Exception");
}
catch(SQLException sql)
{
jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
}
}
if(source==reset)
{
id.setEditable(true);
id.setText(null);
}
if(source==ge)
{
//this.dispose();
res u1=new res();
u1.n1(it,coun,cu);
}
}
bill
CREATE TABLE IF NOT EXISTS `bill` (
`billid` int(10) NOT NULL,
`cus` varchar(20) NOT NULL,
`pho` bigint(10) NOT NULL,
`day` date NOT NULL,
`itid` int(10) NOT NULL,
`count` int(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
공백을 잊지 마십시오 :
"select * from bill where billid="+bid.getText()+" and itid="+id.getText()
그리고 사용하십시오 PreparedStatement
:
PreparedStatement lPreparedStatement = con.prepareStatement("select * from bill where billid=? and itid=?");
lPreparedStatement.setInt(1, Integer.valueOf(bid.getText()));
lPreparedStatement.setInt(2, Integer.valueOf(id.getText()));
더욱이:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다