Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    1

    Arrow Unanswered: 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());
    }
    %>

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •