Results 1 to 3 of 3
Thread: jdbc problem
- 10-04-2011, 10:25 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 20
- Rep Power
- 0
jdbc problem
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.sql.*;
public class frame extends JFrame implements ActionListener {
JLabel rno;
JTextField rtf;
JButton search;
JLabel id;
JTextField idf;
JLabel username;
JTextField uname;
JLabel fathername;
JTextField fname;
JLabel gpa;
JTextField gpaf;
JButton add;
JLabel dline;
JLabel nline;
JButton ok;
JButton cancel;
JPanel p;
String r="";
public frame()
{
super ("Title");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout(FlowLayout.LEFT));
nline = new JLabel(" ");
id = new JLabel("ID ");
idf = new JTextField("",2);
username = new JLabel("Name ");
uname = new JTextField("",20);
fathername = new JLabel ("FatherName");
fname = new JTextField ("",19);
gpa = new JLabel ("GPA ");
gpaf = new JTextField("",4);
add = new JButton("New Entry");
dline = new JLabel ("<=======================================>");
rno = new JLabel("Roll No:");
rtf = new JTextField("",2);
search = new JButton("Search");
search.addActionListener(this);
add(id); add(idf);
add(nline);
add (username); add(uname);
add (fathername); add(fname);
add (gpa); add (gpaf);
add(add);
add(dline);
add (rno); add (rtf); add (search);
p = new JPanel();
add(p);
setVisible(true);
setResizable(false);
}
public static void main(String[] args) {
new frame();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == search)
{
func();
}
}
void func(){
r=rtf.getText();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "student";
String driver = "com.mysql.jdbc.Driver";
try
{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try
{ Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM record WHERE infoid= r ");
System.out.println("name " + "\t" + "fathername: " +"\t" +"gpa"+ "\t" +"id");
while (res.next()) {
String i = res.getString("infoname");
String s = res.getString("infofathername");
String u = res.getString("infogpa");
String t = res.getString("infoid");
System.out.println(i + "\t" + s+ "\t\t" + u+ "\t" + t);
}
}
catch (SQLException s)
{
System.out.println("SQL statement is not executed!");
}
}
catch (Exception f){ f.printStackTrace();}
}
}
- 10-04-2011, 10:27 PM #2
Member
- Join Date
- Sep 2011
- Posts
- 20
- Rep Power
- 0
Re: jdbc problem
Hi, the problem with above code is that when i Enter a number in R.NO. field. & click search to look up the database.. it always says SQL statement is not executed..
- 10-04-2011, 10:27 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
JDBC Problem
By nitishjtm in forum JDBCReplies: 4Last Post: 11-18-2010, 07:25 PM -
jdbc problem!!! pls help
By dilanka007 in forum New To JavaReplies: 1Last Post: 04-14-2010, 02:16 PM -
jdbc problem!!! pls help
By dilanka007 in forum New To JavaReplies: 5Last Post: 01-16-2010, 06:07 PM -
Problem in JDBC
By Preethi in forum New To JavaReplies: 11Last Post: 01-08-2009, 06:18 PM -
JDBC problem
By Swamipsn in forum New To JavaReplies: 1Last Post: 08-13-2007, 07:05 PM
Bookmarks