0% found this document useful (0 votes)
3 views2 pages

Using PreparedStatement in Java SQL

The document provides examples of using PreparedStatement in Java for executing SQL queries. It demonstrates how to select courses from a database using parameters and how to insert new course records. Various methods for setting parameters, such as setInt and setString, are also highlighted.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Using PreparedStatement in Java SQL

The document provides examples of using PreparedStatement in Java for executing SQL queries. It demonstrates how to select courses from a database using parameters and how to insert new course records. Various methods for setting parameters, such as setInt and setString, are also highlighted.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using PreparedStatement

PreparedStatement st=[Link]("select*From course");


PreparedStatement st;
st=[Link]("select*From course where cid=? and cname=?");

set***(int index, Object value)


setInt()
setString()
setDouble()
setFloat()
etc..

int course_id=100;
String course_name="Java";

setInt(1,course_id);
setString(2,course_name);

[Link]();

st=[Link]("insert into course values(?,?,?)");


[Link](1,123);
[Link](3,4500);
[Link](2,"C++");
[Link]();using PreparedStatement

PreparedStatement st=[Link]("select*From course");


PreparedStatement st;
st=[Link]("select*From course where cid=? and cname=?");

set***(int index, Object value)


setInt()
setString()
setDouble()
setFloat()
etc..

int course_id=100;
String course_name="Java";
setInt(1,course_id);
setString(2,course_name);

[Link]();

st=[Link]("insert into course values(?,?,?)");


[Link](1,123);
[Link](3,4500);
[Link](2,"C++");
[Link]();

You might also like