以下是一个按钮的定义事件,a_都是jTextField_.getText();其中有几个是INT型和FLOAT型的,还有一个时间.因为如果jTextField_.getText();为空值(即NULL),则以下的会变成chaxun="insert into huowuliudong values('aaa','aas','dd',,,,,,,);类型的,即有连续的逗号,肯定无法插入.但是在SQL查询分析器里给任何类型的数据要是都加上分号,类似('A','B','','','','');可以运行,所以下面我在各个数据上都加了分号.
public void jButton1_actionPerformed(ActionEvent e) {
charu="insert into huowuliudong values('"+a22+"','"+aaa1+"','"+a7+"','"+a8+"','"+a9+"','"+a18+"','"+a19+"','"+a12+"','"+a10+"','"+a11+"','"+a1+"','"+a3+"','"+a13+"','"+a14+"','"+a16+"','"+a15+"','"+a17+"','"+a4+"','"+a20+"','"+a2+"','"+a5+"','"+a6+"','"+aa1+"');";
String connectionURL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=AAA";
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection connn = DriverManager.getConnection(connectionURL, "sa",
"");
Statement stmt = connn.createStatement();
ResultSet rs = stmt.executeQuery(charu);
} catch(SQLException ex)
{
ex.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
后接!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!后接
但是除法该事件后,却出现:
at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
at 坚持.Frame3.jButton1_actionPerformed(Frame3.java:445)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)............................
为什么呢?该怎么解决啊?是说插入数据不能用stmt.executeQuery(),要用stmt.executeUpdate();吗?但用UPDATE却会出现"Frame3.java": incompatible types; found : int, required: java.sql.ResultSet at line 445, column 33.真的郁闷了``~~~~````