Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa SQL insertion in SQL
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vasu
insertion in SQL
2 Answer(s)      5 years and 11 months ago
Posted in : SQL



Advertisement
View Answers

November 22, 2008 at 3:25 AM


Hi friend,


Code to solve the problem :


import java.io.*;
import java.sql.*;

public class InsertRecords{
public static void main(String[] args) {
System.out.println("Insert records example using prepared statement!");
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/userdetails","root","root";);
try{
String str = "John's";
str = str.replace("'","\\'");

String sql = "INSERT employee (username)VALUES('"+str+"')";

System.out.println(sql + sql);

PreparedStatement prest = con.prepareStatement(sql);

int count = prest.executeUpdate();
System.out.println(count + "row(s) affected");
con.close();
}
catch (SQLException s){
System.out.println(s);
}
}
catch (Exception e){
e.printStackTrace();
}
}
}

Thanks


November 22, 2008 at 3:33 AM


Hi,

In java also we can't use \ directly.. as we use \\ to get printed. So,

For SQL queires we have to give two single quotes like
My name is John's Peter ---> My name is John''s Peter....

So in your java class it self before executing the query add the following line.

ename= ename.replaceAll("'","''");




Related Tutorials/Questions & Answers:
insertion in SQL - SQL
insertion in SQL  Hi! Everybody... i have a problem with sql insertion. When i am inserting values through command i.e. insert into employee... on Insert Query visit to : http://www.roseindia.net/sql/insert.shtml Thanks
insertion in SQL - SQL
insertion in SQL  Query is "insert into employee values('"+eno... in the database because of single code in the name. dbase is MS-SQL emp.name data type... as I know string parameter in SQL is denoted as 'john' . I think thats why
Advertisements
PHP SQL Insertion
PHP SQL Insertion       PHP SQL Insertion is used to execute MySQL queries in PHP script.... Understand with Example The Tutorial illustrate an example from 'PHP SQL Insertion
insertion sort
insertion sort  how many arrays needed for insertion sort and why
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
Insertion into database
Insertion into database  Hi, I need code for inserting the multiple select box values into database.Please do send me the code. Thanks for ur immediate replies its helping a lot
Insertion Sort Applet
Insertion Sort Applet  I need Insertion Sort Applet code was design by Dr. Daniel Liang Please
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
Insertion Sort Applet
Insertion Sort Applet  Please All , I need Insertion sort applet program
Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all
File insertion into oracle database
File insertion into oracle database  How to Read and Insert a file (any format) into a Oracle database
hibernate insertion problem - Hibernate
hibernate insertion problem  Hi , Thanks for the material .Its very gud . when i run FirstExample.java i get the message insertion has been done int the table contact . but whne i look into database data is not inserted
Java insertion sort question
Java insertion sort question  I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write
Insertion Sort Problem
Insertion Sort Problem  So I have this in a class file. It is supposed to be an insertion sorter: int min, index=0, temp; for(int i=0;i<sorted.length;i++){ min=sorted[i]; for(int j=i+1;j<
file insertion - JSP-Servlet
file insertion  How to insert and retrieve .doc files into sql server with example using jsp and servlets
Insertion Sort - Java Beginners
Insertion Sort  Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays LETTERS in alphabetical order from A to Z. Thank you.Hope you gonna helpme
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <..."); String sql="INSERT INTO posting (ignite_id,name,home,location,gender...(sql); ps.executeUpdate(); ps.close(); con.close
insertion error - JSP-Servlet
insertion error  my first jsp page : In this i m getting all the values through a method called getAllDetails,the values are getting inserted but the problem is i have created frames , when i clicking on the link book halls
javascript variable value insertion in DB
javascript variable value insertion in DB  how can I insert javascript variable value into database using php
dynamic delete and insertion in tables
dynamic delete and insertion in tables  hey... i have a problem..I am working on a problem management system..my code for a particular jsp page is as follows in this page i want to show the admin the already present records
dynamic delete and insertion in tables
dynamic delete and insertion in tables  hey... i have a problem..I am working on a problem management system..my code for a particular jsp page is as follows in this page i want to show the admin the already present records
Inserting content(DOM Insertion)
Inserting content(DOM Insertion)       Inserting content(DOM Insertion) Inserting... : DOM insertion DOM insertion, Around DOM
Binary search tree (insertion) urgent!!
Binary search tree (insertion) urgent!!  Create a program to construct a binary search tree consisting of nodes that each stores an integer in Java.Avoid duplication of values when inserting nodes in the tree. When a new leaf
sql
difference between sql and oracle  what is the difference between sql and oracle
Insertion Sort In Java
Insertion Sort In Java     ... In this example we are going to sort integer values of an array using insertion sort. Insertion sorting algorithm is similar to bubble sort. But insertion sort
sql
sql  how to get first row in sql with using where condition in sql? how to get last row in sql with using where condition in sql
sql
sql  I want interview sql questions   Please visit the following link: SQL Tutorials
Sql
Sql  how to find maximum of a101,a102,a103 from a table in sql
 

 

 

DMCA.com