RTRIM语法错误

时间:2013-08-09 07:02:41

标签: java sql trim

我正在使用sql server 2005.我想在sql server 2005中使用RTRIM函数用于具有数据类型Varchar(20)的列名,但是它给出了错误('(')附近的语法不正确。

           try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con =DriverManager.getConnection("jdbc:odbc:project","sa","123456");
                PreparedStatement stmt= con.prepareStatement("insert into driver (RTRIM(Name),Address,Email,Homeph,Cellph,Startdate,Hourlyrate,Image) values(?,?,?,?,?,?,?,?)");
                stmt.setString(1,tx_name.getText());
                stmt.setString(2,tx_address.getText());
                stmt.setString(3,tx_email.getText());
                stmt.setInt(4,Integer.parseInt(tx_homeph.getText()));
                stmt.setInt(5,Integer.parseInt(tx_cellph.getText()));
                String date=cb_date.getSelectedItem().toString()+"-"+cb_month.getSelectedItem().toString()+"-"+cb_year.getSelectedItem().toString();
                stmt.setString(6,date);
                stmt.setInt(7,Integer.parseInt(tx_hourlyrate.getText()));
                stmt.setString(8,tx_image.getText());
                stmt.executeUpdate();
                JOptionPane.showMessageDialog(f,"Data Saved","Save",JOptionPane.INFORMATION_MESSAGE);
            }
            catch(Exception en)
            {
                JOptionPane.showConfirmDialog(f,en);
            }

1 个答案:

答案 0 :(得分:2)

您应该在插入的VALUE bing上使用RTRIM,而不是列名。

RTRIM (Transact-SQL)

  

截断所有尾随空格后返回一个字符串。