| |

VerySource

 Forgot password?
 Register
Search
View: 1359|Reply: 10

Fuzzy query on the database in java

[Copy link]

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-10-12 12:30:01
| Show all posts |Read mode
As the title, why always report such a mistake
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer] Line 1: There is a syntax error near'%8%'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
at leasecar.SafeInfo.getData(SafeInfo.java:30)
at leasecar.SafeInfo.getMyTabelModel(SafeInfo.java:112)
at leasecar.SafeInfoPanel.jButton1_actionPerformed(SafeInfoPanel.java:132)
at leasecar.SafeInfoPanel$SafeInfoPanel_jButton1_actionAdapter.actionPerformed(SafeInfoPanel.java:252)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.NullPointerException
at leasecar.SafeInfo.getMyTabelModel(SafeInfo.java:113)
at leasecar.SafeInfoPanel.jButton1_actionPerformed(SafeInfoPanel.java:132)
at leasecar.SafeInfoPanel$SafeInfoPanel_jButton1_actionAdapter.actionPerformed(SafeInfoPanel.java:252)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


P. S.
I use the same statement to query in sql server, and the query can be performed normally.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-12 14:00:01
| Show all posts
Post the code
ok!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-12 14:15:01
| Show all posts
Look for the formatting syntax in Java, your SQL statement may have syntax errors
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-10-12 14:30:01
| Show all posts
String a = myselect.getSelectedItem().toString();
        String b = con.getText();
        SafeInfo ss = new SafeInfo();
        MyTabelModel m;
        if (!a.equals("all information")) {
            if (a.equals("Insurance Number")) {
                int flag = 0;
                char c;
                for (int i = 0; i <b.length(); i++) {
                    c = b.charAt(i);
                    if (Character.isLetter(c)) {
                        flag = 1;
                    }
                }
                if (flag == 1) {
                    javax.swing.JOptionPane.showMessageDialog(null,
                            "<html><font color=red>Please enter a number!</font></html>",
                            "System Message", JOptionPane.ERROR_MESSAGE);
                    m = null;
                    this.con.setText("");
                    this.con.requestFocus();
                } else {
     //My query statement m = ss.getMyTabelModel("select * from SafeInfo where "+ a +
                                           "like'%" + b + "%'");
                }
            } else {
     //My query statement is the error reported here m = ss.getMyTabelModel("select * from SafeInfo where "+ a +
                                       "like'%" + b + "%'");
            }
        } else {
            m = ss.getMyTabelModel("select * from SafeInfo");
        }
        if (m != null) {
            this.useTabel.setModel(m);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null,
                    "<html><font color=red>There is no data you are looking for, please check carefully and then check</font></html>",
                    "System Message", JOptionPane.ERROR_MESSAGE);
            this.con.setText("");
            this.con.requestFocus();
        }
    }


    public void myselect_actionPerformed(ActionEvent e) {
        if (this.myselect.getSelectedItem().toString().equals("all information")) {
            this.con.setText("");
            this.con.setEditable(false);
        } else {
            this.con.setEditable(true);
        }
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-10-12 18:15:01
| Show all posts
Print out sql to see if it can be run directly. This is not java's fault
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-10-12 20:00:01
| Show all posts
My sql statement can run very well in sql server...
I got an error and died in java.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-12 20:15:01
| Show all posts
Add a space before like to see, OK?
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-10-12 22:15:01
| Show all posts
I added it...no, fainted...the masters all come out to help the puppet.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-12 22:30:02
| Show all posts
There is no space in front of like. Of course, alike ‘%8%’ will be wrong. You will find out if you go to sql server and execute it.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-12 23:15:01
| Show all posts
Add a space before like.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list