Results 1 to 3 of 3

Thread: jdbc problem

  1. #1
    Shahnawaz is offline Member
    Join Date
    Sep 2011
    Posts
    20
    Rep Power
    0

    Default 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();}


    }

    }

  2. #2
    Shahnawaz is offline Member
    Join Date
    Sep 2011
    Posts
    20
    Rep Power
    0

    Default 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..

  3. #3
    Shahnawaz is offline Member
    Join Date
    Sep 2011
    Posts
    20
    Rep Power
    0

    Default Re: jdbc problem

    P.S: i am using wampserver with mysql as u can see up there..

Similar Threads

  1. JDBC Problem
    By nitishjtm in forum JDBC
    Replies: 4
    Last Post: 11-18-2010, 06:25 PM
  2. jdbc problem!!! pls help
    By dilanka007 in forum New To Java
    Replies: 1
    Last Post: 04-14-2010, 01:16 PM
  3. jdbc problem!!! pls help
    By dilanka007 in forum New To Java
    Replies: 5
    Last Post: 01-16-2010, 05:07 PM
  4. Problem in JDBC
    By Preethi in forum New To Java
    Replies: 11
    Last Post: 01-08-2009, 05:18 PM
  5. JDBC problem
    By Swamipsn in forum New To Java
    Replies: 1
    Last Post: 08-13-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •