Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double quotes

Status
Not open for further replies.

Khanjan

Programmer
Feb 24, 2004
41
NL
I am using Insert statment in JSP code.

statement.executeUpdate("INSERT INTO ADMIN VALUES ('"+lastParam+"','"+databaseinvoer+"','"+phoneParam+"')");

Where datbaseinvoer contains the article that i want to store.

When i use "" or '' within mine article, it does not works. If i put \ before each quote, it does works.

But i dont want to do that each time, How can i do this the easiest way?

 
Use PreparedStatement instead. e.g.

Code:
Connection con = DriverManager.getConnecction(.....);
PreparedStatement stmt = con.prepareStatement("INSERT INTO ADMIN VALUES ?, ?, ?");
stmt.setString(1, lastParam);
stmt.setString(2, databaseinvoer);
stmt.setString(3, phoneParam);
stmt.execute();
 
This is my code, but i dont know what is wrong.

<P> Update Database Content
<FORM ACTION="updatePhonebook.jsp" METHOD="POST">
Last Name: <INPUT TYPE=TEXT NAME=lastIn><BR>
Password: <INPUT TYPE=TEXT NAME=firstIn><BR>
Heel verhaal<TEXTAREA NAME="content" ROWS="" COLS="" value=""></TEXTAREA>

<INPUT TYPE=Submit VALUE="Add to Database">
</FORM>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/fahim?user=fahim&password=fahim");


String a = request.getParameter("lastIn");
String b = request.getParameter("firstIn");
String c = request.getParameter("content");

String sql = "INSERT INTO ADMIN VALUES (?, ?, ?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setInt(1, a);
statement.setString(2, b);
statement.setString(3, c);
statement.executeQuery();
%>
 
Hi,

statement.setInt(1, a);

Change it to..

statement.setString(1, a); coz "a" is a String.

if you want to pass int then

statement.setInt(1, Integer.parseInt(a));

Cheers
Venu


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top