I have been able to successfuly connect to my Oracle Database using
the JDBC but my select statement that I have used so far is static
and I would like to make it dynamic and pass a value to it. Can
anyone help me out and tell me how I can do this?
Here's a little portion of the code. I want to pass a value in place
of the log_field5 in the select statement.
public class tledatabase{
public static void main(String [] args){
tledatabase thisTest = new tledatabase();
thisTest.test();
}
public void tledatabase(){}
public void test(){
System.out.println("about to connect");
connect();
System.out.println("Connection complete");
}
public void connect(){
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection
("jdbc:oracle:thin:@0.0.0.0:1521:DATA", "user", "password");
if (conn!=null){
System.out.println("connection made");
Statement stmt = null;
ResultSet rset = null;
stmt = conn.createStatement();
// Execute Statement to get product Information
from the Database
rset = stmt.executeQuery(" SELECT log_field1 " +
" FROM " + "transaction0 where log_field5
= '596612'");
while (rset.next())
System.out.println(rset.getString ("log_field1"));
// Close Result Set and Statement
rset.close();
stmt.close();