If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > String literal error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-10, 21:09
antonyajay21 antonyajay21 is offline
Registered User
 
Join Date: Nov 2010
Posts: 1
Arrow String literal error

Hey, this is the source code of a jsp file.Happened to get an error at line number 30 which states......String query="INSERT INTO DB2ADMIN.STUDENT (USN, NAME, SEM, BRANCH, DOB) VALUES ('"+strUsn+"','"+strName+"','"+strSem+"','"+strBra nch+"','"+strDob+"')";.........I wonder if it is a syntax error.Pls help. The error message saystring literal is not properly closed by a double quote.



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*;"%>

<%

Connection con = null; // Create an object of Connection class
String url = "jdbc:db2://localhost:50000/"; // The Database url
String db = "Exercise"; //Database Name
String driver = "com.ibm.db2.jcc.DB2Driver"; // Database driver for DB2
String user = "db2admin"; //DB2 Username
String pass = "admin"; //DB2 Password

try
{
//To Establish Database Connection
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);

// Obtain the student details from the form
String strUsn = request.getParameter("usn");
String strName = request.getParameter("name");

// Converting the String to Integer Type
int strSem = Integer.parseInt(request.getParameter("sem"));

String strBranch = request.getParameter("branch");
String strDob = request.getParameter("dob");

//Insert query to enter the details to database
String query="INSERT INTO DB2ADMIN.STUDENT (USN, NAME, SEM, BRANCH, DOB) VALUES ('"+strUsn+"','"+strName+"','"+strSem+"','"+strBra nch+"','"+strDob+"')";

con.setAutoCommit(false);

PreparedStatement ps = con.prepareStatement(query);

int rowsUpdated = ps.executeUpdate();

// Condition to check if there was any data inserted to the db
if(rowsUpdated>0){%>

<h2>Student Details Inserted successfully! </h2>
<% }
else{%>
<h2>Operation Failed!! <br />
Check the Stack trace to identify the mistake!! :-)</h2>
<%}
// Commit the changes
con.commit();

// Close the connection
con.close();
}

// Handle the Exception
catch (Exception e)
{
e.printStackTrace();
System.out.print(e.getMessage());
}
%>
Reply With Quote
  #2 (permalink)  
Old 11-17-10, 21:16
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by antonyajay21 View Post
The error message saystring literal is not properly closed by a double quote.
Hey, since SQL string literals are enclosed in single, not double quotes, I suspect your error message refers to the java code.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On