这部分应该添加一列火车到我的数据库中的TRAININFO表。我必须使用mysql。为什么此代码无法正常工作?
因此,在添加火车之前我必须看到一些限制条件。
jTextField1.getText()
;火车票。不应该超过6个字符,它应该是一个整数。jTextField2.getText()
; TrainName。不应超过30个字符。jTextField10,jTextField12
分别有Depttime和araivaltime。 它有5个字符,“hr:mn”所以我必须检查'hr'< = 24和'mn'< = 59。- 如果
jTextField3.getText()==0
(ac1教练的数量)的值,则ac1教练的训练(tfac1)也应该是== 0。
记住这一点,我试图编码它。但它不起作用。
当我运行此有一个错误消息。
请告诉我我错了。
堆栈跟踪:[Ljava.lang.StackTraceElement; @ e596c9
好继承人应该是如何工作的:
String m="-",t="-",w="-",th="--",f="-",st="--",s="-",runson;
if(jCheckBox1.isSelected()==true)
{
m="m";
}
if(jCheckBox2.isSelected()==true)
{
t="t";
}
if(jCheckBox3.isSelected()==true)
{
w="w";
}
if(jCheckBox4.isSelected()==true)
{
th="th";
}
if(jCheckBox5.isSelected()==true)
{
f="f";
}
if(jCheckBox6.isSelected()==true)
{
st="st";
}
if(jCheckBox7.isSelected()==true)
{
s="s";
}
runson=m+t+w+th+f+st+s;
int h1=Integer.valueOf(jTextField10.getText().substring(0,2));
int mins1=Integer.valueOf(jTextField10.getText().substring(3,5));
int h2=Integer.valueOf(jTextField12.getText().substring(0,2));
int mins2=Integer.valueOf(jTextField12.getText().substring(2,3));
String time1=jTextField10.getText().substring(0,2)+jTextField10.getText().substring
(2,3)+jTextField10.getText().substring(3,5);
String time2=jTextField12.getText().substring(0,2)+jTextField12.getText().substring
(2,3)+jTextField12.getText().substring(3,5);
String tfac1=jTextField13.getText();
String tfac2=jTextField14.getText();
String tfac3=jTextField15.getText();
String tfsl=jTextField16.getText();
if(Integer.valueOf(jTextField3.getText())==0)
{
tfac1="0";
}
if(Integer.valueOf(jTextField4.getText())==0)
{
tfac2="0";
}
if(Integer.valueOf(jTextField5.getText())==0)
{
tfac3="0";
}
if(Integer.valueOf(jTextField6.getText())==0)
{
tfsl="0";
}
try
{
Class.forName("java.sql.DriverManager");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/bvdb","root","enter");
Statement stm=con.createStatement();
int n=jTextField1.getText().trim().length();
int m=jTextField2.getText().trim().length();
if(n<=6 && m<=30 && h1<=24 && h2<=24 && mins1<=59 && mins2<=59)
//This should check the constraints(1,2,3).if the condition is true the following statement will be executed ..else the catch block should be executed. But this doesn't seem to happen when i run the code. There is always an Exception raised.//
{
String q="INSERT INTO TRAININFO VALUE ("+jTextField1.getText()+",'"+jTextField2.getText()+"','"+jTextField9.getText()+"','"+time1+"','"+jTextField11.getText()+"','"+time2+"','"+runson+"',"+tfac1+","+tfac2+ ","+tfac3+","+tfsl+","+jTextField3.getText()+","+jTextField4.getText()+","+jTextField5.getText()+","+jTextField6.getText()+")";
stm.executeUpdate(q);
System.out.print("ADDED");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this,"Enter valid details");
}
请花些时间格式化您的代码! – Baby
请继续阅读之前了解循环。 –
请在你的问题中包含你的堆栈跟踪。将自己的问题回复给自己,并注意它没有真正描述发生了什么问题......在我们提供帮助之前,我们需要更多信息。 –