import java.sql.*;
public class tp{
public static void main(
String[] args) {
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","system","password");
Statement stmt = conn.createStatement();
String an="first";
System.out.println(an);
// a select query
ResultSet rset = stmt.executeQuery ("SELECT * FROM application where appname ='&an'");
while (rset.next()) {
System.out.println(rset.getString(1));
System.out.println(rset.getString(2));
System.out.println(rset.getString(3));
}
rset.close();
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
}
}
}
this is the code which I tried to get the values from table application having appname='first' using a variable an but I failed... (this is just a part of server client simulation where you get the value 'first' from client which you assign to a variable 'an' in the server and try to access the database with variable 'an')