Results 1 to 9 of 9

Thread: swing coding

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Unhappy swing coding

    hiiiii
    actualy i wanna retrive data from MS Acsess in java swing
    but i have an error
    so u plz help me in solving dat error.....thanx
    this is my code
    there is two programs one for database and second one is for where data is shown in table.

    .................................................. .................................................. ....
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Logger extends JFrame implements ActionListener
    {
    JButton jb1,jb2;
    JLabel jl1,jl2,jl3;
    JTextField jtf;
    JPasswordField jp;
    String x;
    String y;
    public Logger()
    {
    jl1=new JLabel("<html><center><font face=Maiandra GD size=5><u>Welcome to</u><p>School Management System</font></html>");
    Container cont=getContentPane();
    jl2=new JLabel("Enter Name");
    jl3=new JLabel("Enter Password");
    JPanel jpp=new JPanel();
    jpp.setLayout(null);
    jtf=new JTextField(10);
    jp=new JPasswordField(10);
    jpp.add(jl1);
    jpp.add(jl2);
    jpp.add(jl3);
    jpp.add(jtf);
    jpp.add(jp);
    jb1=new JButton("Save");
    jb1.addActionListener(this);
    jpp.add(jb1);
    jl1.setBounds(80,5,300,80);
    jl2.setBounds(100,75,120,10);
    jl3.setBounds(100,78,300,80);
    jtf.setBounds(205,75,120,20);
    jp.setBounds(205,105,120,20);
    jb1.setBounds(205,135,70,29);
    cont.add(jpp);
    setTitle("Log In");
    setSize(500,200);
    setVisible(true);
    }
    public void actionPerformed(ActionEvent ae)
    {
    x=jtf.getText();
    y=jp.getText();
    JDta jxy=new JDta();
    jxy.putting(x,y);
    dispose();
    new Salary();
    }
    public static void main(String aa[])
    {
    new Logger();
    }
    }


    .................................................. .................................................. ....
    import java.sql.*;
    public class JDta
    {
    public void putting(String x,String y)
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:stu","" ,"");
    PreparedStatement stmt=con.prepareStatement("insert into data values(?,?)");
    stmt.setString(1,x);
    stmt.setString(2,y);
    stmt.executeUpdate();
    stmt.close();
    con.close();
    }
    catch(Exception er)
    {
    }
    }

    public boolean checking(String x,String y)
    {
    int coun=0;
    boolean bb;
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:exams", "","");
    PreparedStatement stmt=con.prepareStatement("select * from data where name=? and pass=?");
    stmt.setString(1,x);
    stmt.setString(2,y);
    ResultSet rs=stmt.executeQuery();
    while(rs.next())
    {
    coun++;
    }
    stmt.close();
    con.close();
    }
    catch(Exception er)
    {
    }
    if(coun>0)
    bb=true;
    else
    bb=false;
    return bb;
    }
    }

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    If you want help, can I suggest:
    - don't just post a big slab of poorly formatted code and say "I have a problem"
    - instead, describe precisely what problem you're having, and try and hone it down to a few lines.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  4. #4
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default thanx for replying

    :)swing coding
    hiiiii
    thanx for replying
    but that was not solution of problem
    ok if you remove new salary(); then still the data from database is nt showing.
    actualy i wanna retrive data from MS Acsess in java swing
    but i have an error
    so u plz help me in solving dat error.....thanx
    this is my code
    there is two programs one for database and second one is for where data is shown in table.

    .................................................. .................................................. ....
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Logger extends JFrame implements ActionListener
    {
    JButton jb1,jb2;
    JLabel jl1,jl2,jl3;
    JTextField jtf;
    JPasswordField jp;
    String x;
    String y;
    public Logger()
    {
    jl1=new JLabel("<html><center><font face=Maiandra GD size=5><u>Welcome to</u><p>School Management System</font></html>");
    Container cont=getContentPane();
    jl2=new JLabel("Enter Name");
    jl3=new JLabel("Enter Password");
    JPanel jpp=new JPanel();
    jpp.setLayout(null);
    jtf=new JTextField(10);
    jp=new JPasswordField(10);
    jpp.add(jl1);
    jpp.add(jl2);
    jpp.add(jl3);
    jpp.add(jtf);
    jpp.add(jp);
    jb1=new JButton("Save");
    jb1.addActionListener(this);
    jpp.add(jb1);
    jl1.setBounds(80,5,300,80);
    jl2.setBounds(100,75,120,10);
    jl3.setBounds(100,78,300,80);
    jtf.setBounds(205,75,120,20);
    jp.setBounds(205,105,120,20);
    jb1.setBounds(205,135,70,29);
    cont.add(jpp);
    setTitle("Log In");
    setSize(500,200);
    setVisible(true);
    }
    public void actionPerformed(ActionEvent ae)
    {
    x=jtf.getText();
    y=jp.getText();
    JDta jxy=new JDta();
    jxy.putting(x,y);
    dispose();

    }
    public static void main(String aa[])
    {
    new Logger();
    }
    }


    .................................................. .................................................. ....
    import java.sql.*;
    public class JDta
    {
    public void putting(String x,String y)
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbcdbc:stu","" ,"");
    PreparedStatement stmt=con.prepareStatement("insert into data values(?,?)");
    stmt.setString(1,x);
    stmt.setString(2,y);
    stmt.executeUpdate();
    stmt.close();
    con.close();
    }
    catch(Exception er)
    {
    }
    }

    public boolean checking(String x,String y)
    {
    int coun=0;
    boolean bb;
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbcdbc:exams", "","");
    PreparedStatement stmt=con.prepareStatement("select * from data where name=? and pass=?");
    stmt.setString(1,x);
    stmt.setString(2,y);
    ResultSet rs=stmt.executeQuery();
    while(rs.next())
    {
    coun++;
    }
    stmt.close();
    con.close();
    }
    catch(Exception er)
    {
    }
    if(coun>0)
    bb=true;
    else
    bb=false;
    return bb;
    }
    }

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    The : is probably missing in your code

    Connection con=DriverManager.getConnection("jdbc: odbc:exams", "","");

    There wont be any space between : and o , just for formatting issues of the forum I included a space.

  7. #7
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default

    hiiiiiiii
    i have a question dat
    if we use our swing code of different class and copy it in any netbens 6.5project,then in net beans 6.5 why in dat option for Design View is not shows...

    plz reply as soon as possible......
    thank you

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    A great resource that has helped me and will probably help you is an article entitled How To Ask Questions The Smart Way. It will tell you how to formulate your questions so that the folks here will be better able to answer them. Good luck.

  9. #9
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default

    you did nt mention here which type of error you had got?
    first do it.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. coding help
    By accies76 in forum New To Java
    Replies: 5
    Last Post: 11-12-2008, 08:15 PM
  2. Coding Java on a Mac
    By Menre in forum New To Java
    Replies: 5
    Last Post: 05-06-2008, 05:49 AM
  3. Need Help Coding Project
    By Bascotie in forum New To Java
    Replies: 9
    Last Post: 04-27-2008, 11:31 PM
  4. Problem in my coding
    By one198 in forum New To Java
    Replies: 9
    Last Post: 08-09-2007, 10:07 AM
  5. Help with program coding
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 07:16 AM

Posting Permissions

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