i want to get records from msaccess when the pin number start from 'twt000'. I am using one variable name is pinnumber to store the value.

String pinnumber='twt000'

how to fetch records from msaccess database.

pst=con2.prepareStatement("Select * from pin_numbers where pin_number like '?*'");
					pst.setString(1,pin); 
					rs2=pst.executeQuery();

Please any one help me.

Recommended Answers

All 3 Replies

Your query is wrong. Do some studying about sql. If you want to use ? and prepared statements don't use quotes. Use this:

"Select * from pin_numbers where pin_number like ?"

pst.setString(1,pin);

If you want to search rows that have this: "twt000" inside their value, then this '*' will not work with sql.
Use:

"Select * from pin_numbers where pin_number like '%" + pinnumber + "%'";

Not prepared statement.

Thankyou. My query is run

You can also use PreparedStatement which utilizes wildcards; just make sure that the "pin" you are setting already has those wildcard characters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.