| Author |
use of createStatement in JDBC
|
Mukes Patel
Greenhorn
Joined: Nov 13, 2012
Posts: 2
|
|
[code=java][package com.jlcindia.jdbc;
import java.sql.*;
public class Lab1 {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:JLCDSN", "system", "s2dio");
String sql = "insert into customers values(1,'sri','sri@jlc',123,'Blore');";
Statement st = con.createStatement();
int x = st.executeUpdate(sql);
if (x == 0) {
System.out.println("Record is not Inserted");
} else {
System.out.println("Rocord is Inserted");
}
st.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
]
|
 |
Mukes Patel
Greenhorn
Joined: Nov 13, 2012
Posts: 2
|
|
Mukes Patel wrote:[code=java][package com.jlcindia.jdbc;
import java.sql.*;
public class Lab1 {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc  dbc:JLCDSN", "system", "s2dio");
String sql = "insert into customers values(1,'sri','sri@jlc',123,'Blore');";
Statement st = con.createStatement();
int x = st.executeUpdate(sql);
if (x == 0) {
System.out.println("Record is not Inserted");
} else {
System.out.println("Rocord is Inserted");
}
st.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
]
What is use of createStatement in this program? as it is used to Creates a Statemen object for sending SQL statements to the database. I mean to ask is it used to send String sql = "insert into customers alues(1,'sri','sri@jlc',123,'Blore');"; statement in the above program to the database. please clear my doubts.
|
 |
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
|
|
Java Doc Reference:
createStatement()
Creates a Statement object for sending SQL statements to the database.
execute(String sql)
Executes the given SQL statement, which may return multiple results.
|
Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
|
 |
 |
|
|
subject: use of createStatement in JDBC
|
|
|