Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd backslash to Varchar in MySQL
    primarykey
    data
    text
    <p>I've created this little quiz for a school project using Java and MySQL. Now My project runs fine but as an experiment i tried to add images in my question. The Question jFrame takes the question and all options directly from a database called ques having 8 columns last of which is "path" which is a varchar(500). Here is my Java code to add questions :-</p> <pre><code>try { Class.forName("java.sql.Driver"); Connection con = (Connection) DriverManager.getConnection(jdbcurl, user, pass); Statement st = con.createStatement(); ResultSet rt = st.executeQuery("SELECT qno from ques order by qno desc limit 1"); // get last qno primary key for (; rt.next(); ) { qno = (Integer) rt.getObject(1); // save qno as int } nqno = qno + 1; // create new qno if (path == null){ String query1 = "insert into ques values (" + nqno + ",'" + question + "','" + ans1 + "','" + ans2 + "','" + ans3 + "','" + ans4 + "','" + ca + "',null);"; // ca is correct answer and null is path Statement st1 = con.createStatement(); st1.executeUpdate(query1); System.out.println("query : "+query1); JOptionPane.showMessageDialog(this, "Question added successfully! Without Image");} else { String query1 = "insert into ques values (" + nqno + ",'" + question + "','" + ans1 + "','" + ans2 + "','" + ans3 + "','" + ans4 + "','" + ca + "','"+path+"');"; System.out.println("query :" +query1); Statement st1 = con.createStatement(); st1.executeUpdate(query1); JOptionPane.showMessageDialog(this, "Question added successfully! with image"); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error in code"); </code></pre> <p>The query sent was query :insert into ques values (12,'123','123','123','123','123','123','F:\JavaQuiz\src\javaquiz\About.png'); All okay, no exception handled. But in the SQL the path is saved so :- F:JavaQuizsrcjavaquizAbout.png </p> <p>The database omits the backslashes. I want it not to do so. So that later I can call this link in my Question.java </p> <p>Please.. Any suggestion?</p> <p>(I'm sorry I'm new to programming so sorry if this is a dumb question)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload