I can not run the code please help me to solve it.Actually I am trying to take the string input in the code from the text field and place it on the sql query like this:
ResultSet rs=stmt.executeQuery("select ' "+cid+" ' from data");
which will show me the information from the database but it's not working.When I am writing the code like this:
ResultSet rs=stmt.executeQuery("select * from data");
it is working.
Can you please help me.The full code is attached.
.......................................
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
class nishan implements ActionListener{
JFrame f1=new JFrame("New");
JLabel l1=new JLabel("column");
JButton b1=new JButton("Done");
JTextField t1=new JTextField();
nishan(){
b1.setBounds(10, 170,90, 70);
l1.setBounds(10,20,80,80);
t1.setBounds(60,50,150,20);
f1.add(b1);
f1.add(l1);
f1.add(t1);
b1.addActionListener(this);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setLayout(null);
f1.setVisible(true);
f1.setLocationRelativeTo(null);
f1.setSize(500, 370);
}
public void actionPerformed(ActionEvent e) {
String cid = new String(t1.getText());
if(e.getSource()==b1){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","almaksud");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select '"+cid+"' from data");
while(rs.next())
System.out.println(rs.getString("name")+" "+rs.getInt("id"));
conn.close();
}catch(Exception d){ System.out.println(e);}
}
}
}
public class justdo {
public static void main(String[] args) {
new nishan();
}
}