查看: 697|回复: 2
|
救命啊!java问题,资料进不到database
[复制链接]
|
|
各位大哥/大姐:
我的program,全部都进不到我的database
这是其中一个class的coding
请把它copy and paste进Jcreator或任何java tool
它带有main program可以单独运行
我的问题是,我想把用户输入的iTable,iMid,iMquantity放进我的microsoft access database...table name Order 里的TableNo,Mid,Quantity (他们都是TEXT的,那个table里也只有他们3个成员)
结果,我每次点击ADD后,都显示FAIL FAIL FAIL (SQL EXCEPTION)
请各位高手帮帮我啊!实在是很赶了我才上论坛求救。。。
如果需要任何别的资料,联络我msn: csleon86@hotmail.com
thanks so much!!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class AddMeal extends JFrame implements ActionListener
{
private JLabel Table;
private JLabel Mid;
private JLabel Mname;
private JLabel Mquantity;
private JLabel Mprice;
//private int iTableNumber;
private JTextField iTable;
private JTextField iMid;
private JTextField iMname;
private JTextField iMquantity;
private JTextField iMprice;
private String TableNumber;
private JButton iAdd;
private JButton iClose;
JPanel fpanel;
String url;
Connection connect;
public AddMeal()
{
System.out.println(TableNumber);
setTitle("RAS Add Meal"
setLocation(200,200);
setVisible(true);
Container contentPane;
contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
try
{
url = "jdbcdbc:Restaurant";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
connect = DriverManager.getConnection( url );
System.out.print( "Connection successful\n" );
}
catch ( ClassNotFoundException cnfex )
{
cnfex.printStackTrace();
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
}
catch ( Exception ex )
{
ex.printStackTrace();
}//code to connect database
fpanel=new JPanel();
Table=new JLabel("Table No"
iTable=new JTextField(20);
iTable.setToolTipText("Enter Table No"
Mid=new JLabel("Meal ID"
iMid =new JTextField(20);
iMid.setToolTipText("Enter Meal ID"
Mname=new JLabel("Meal Name"
iMname=new JTextField(20);
iMname.setToolTipText("This is the meal name for the ID you input"
Mquantity=new JLabel("Quantity"
iMquantity=new JTextField(20);
iMquantity.setToolTipText("quantity of order"//need to set the default to 1..havent set
Mprice=new JLabel("rice"
iMprice=new JTextField(20);
iMprice.setToolTipText("Total price for this meal"
iAdd= new JButton ("ADD"
iAdd.setToolTipText("Add this order"
iAdd.setActionCommand("add"
iAdd.addActionListener(this);
iClose= new JButton ("CLOSE"
iClose.setToolTipText("Close this Add Meal Interface"
iClose.setActionCommand("close"
iClose.addActionListener(this);
fpanel.add(Table);
fpanel.add(iTable);
fpanel.add(Mid);
fpanel.add(iMid);
fpanel.add(Mname);
fpanel.add(iMname);
fpanel.add(Mquantity);
fpanel.add(iMquantity);
fpanel.add(Mprice);
fpanel.add(iMprice);
fpanel.add(iAdd);
fpanel.add(iClose);
fpanel.setLayout(new GridLayout(6,2));
contentPane.add(fpanel,BorderLayout.NORTH);
pack();
setSize(500,200);
show();
}
public void actionPerformed(ActionEvent event)
{
if (event.getActionCommand().equalsIgnoreCase("add")
{
try{
String action=("INSERT INTO Order" + "(TableNo,Mid,Quantity)"
+"VALUES('"+ iTable.getText()+"','"+ iMid.getText()+"','"+ iMquantity.getText()+"')"
Statement S=connect.createStatement();
ResultSet rs=S.executeQuery("SELECT * FROM Order"
S.executeUpdate(action);
JOptionPane.showMessageDialog(null,"Stock Record has been successfully insert!"
}
catch(Exception E){
System.out.println("FAIL FAIL FAIL"
}
if (event.getActionCommand().equalsIgnoreCase("close")
{
MealOrdering abc1=new MealOrdering();
setVisible(false);//close this interface and call MealOrdering Interface
}
public static void main( String args[] )
{
AddMeal model=new AddMeal();
}
}
} |
|
|
|
|
|
|
|
发表于 14-7-2006 02:14 PM
|
显示全部楼层
原帖由 csleon86 于 14-7-2006 12:50 PM 发表
各位大哥/大姐:
我的program,全部都进不到我的database
这是其中一个class的coding
请把它copy and paste进Jcreator或任何java tool
它带有main program可以单独运行
我的问题是,我想把用户输入的iTable ...
别急,慢慢把问题写出来,大家才能帮你呀!你的add block 的exception 只是print System.out.println("Fail Fail Fail"), 那要如何作debuging 呢?你应该print exception stack 出来, 例如:E.printStackTrace(), 这样你才能找出那里出问题。
还有你这里的code 有一点怪,
Statement S=connect.createStatement();
//读,但没见你用里面的资料,如果没用,把以下的code comment
ResultSet rs=S.executeQuery("SELECT * FROM Order"); |
|
|
|
|
|
|
|
楼主 |
发表于 14-7-2006 03:15 PM
|
显示全部楼层
谢谢大家,问题已经解决了!!! 问题是microsoft access 里order 是reserve word,不能用来当table name...
谢谢大家。。。这个帖可以珊了 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|