*
The moose likes JDBC and the fly likes use of createStatement in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "use of createStatement in JDBC" Watch "use of createStatement in JDBC" New topic
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("jdbcdbc: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("jdbcdbc: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: 1321

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..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
 
subject: use of createStatement in JDBC