Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 13:43

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Little Question about JDBC & String Handling

Discussion on Little Question about JDBC & String Handling within the Java forum part of the Coders Den category.

Closed Thread
 
Old   #1


 
Liihes's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 2,728
Received Thanks: 934
Little Question about JDBC & String Handling

The posts are including apostrophes. So how to suppress them while executing the SQL Statement?
Code:
 term.replaceAll("'","''");
Should I use this or is there another good way?

Thanks for your help
Code:
	
String uString = txtString.getText();
String cString = uString .replaceAll("'","''");
StringBuilder sb = new StringBuilder();

		sb.append("UPDATE `tablename` SET ");

		if (!cString.isEmpty()) {
			sb.append("colum='" + cString+ "'");
		}

                sb.append(" WHERE .... ";");
Liihes is offline  
Old 06/29/2016, 01:20   #2
 
Zunft's Avatar
 
elite*gold: 0
Join Date: Mar 2013
Posts: 3,184
Received Thanks: 1,317
You should take a look at . With Statements you're able to build and execute your SQL Statement.

When it comes to variables with special characters you should use . The magic happens by not inserting the variables directly in the Statment String but parsing them into the Statement String using Wildcards. This looks somehow like this:

Code:
private void updateTable(Connection con)
{
    PreparedStatement stmt = null;
    //'?' is a Wildcard 
    String update = "UPDATE ? SET [...]";

    try
    {
        stmt = con.prepareStatement(update);
        //IMPORTANT: First index of wildcard is 1
        stmt.setString(1, "your special string");

        stmt.executeUpdate();
        con.commit();
    }
    catch(SQLException e)
    {
        e.printStackTrace();
    }
}
Zunft is offline  
Thanks
2 Users
Old 06/29/2016, 01:38   #3


 
Liihes's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 2,728
Received Thanks: 934
Quote:
Originally Posted by Mr. Boombastic View Post
Question solved, close please
Liihes is offline  
Old 06/29/2016, 10:05   #4
dotCom
 
Devsome's Avatar
 
elite*gold: 12400
The Black Market: 104/0/0
Join Date: Mar 2009
Posts: 15,880
Received Thanks: 4,386
Quote:
Originally Posted by Liihes View Post
Question solved, close please
#closed as request
Devsome is offline  
Thanks
1 User
Closed Thread


Similar Threads Similar Threads
[Question] Item String Keys ?
10/26/2014 - S4 League - 2 Replies
Hey, I habe eine Frage über Item String Keys.. Wie kann ich diese also die Item String Keys herausfinden ?
[Question]New Role String Packet
11/16/2011 - CO2 Private Server - 19 Replies
Version: 5017 Problem: After I sent the "NEW_ROLE" message packet to the client to allow it to create a new character, the client is sent to the char creation screen just fine. But after the client goes to create a character, the server doesn't receive any packets back. Current Packet: Any ideas on some things to try to get the client to respond?
[Question]New way of packet handling?
01/26/2011 - CO2 Private Server - 16 Replies
I have been thinking, and to me it seems that a lot of the packet handlers (especially LOTF) are pretty large. Would it take up more resources to do something more dynamic such as the following? This is just an example obviously. But the main concept is there. The void would be your PacketID, the Arg1 would be your data. And it simply calls the method immediately rather then going through a case? class Program { static void Main(string args) { string...
[Question]Teleporter string
12/30/2009 - Dekaron Private Server - 8 Replies
I edited a teleporter, The location are good, but the names are wrong Anyone can help? http://img706.imageshack.us/img706/288/naamlooscz .png
[Question] string folder Related !!
10/01/2009 - Dekaron Private Server - 0 Replies
string folder Related !! share a folder in a folder in the string skilldesc.csv / skillname.csv 255 lines of the file exceeds the client hangs. How to modify, where am I?:confused: And 6 Accessories What am I to put the item?:confused:



All times are GMT +2. The time now is 13:43.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.