Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Not seeing the result in the databse

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Not seeing the result in the databse

    Here's my code for a button that add values into an empty database.
    The program skips system.out.println("1");
    And the database is still empty. I can't figure out why


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String url = "jdbc:mysql://localhost:3306/xxxxxxxxxxxx";
    String driver = "com.mysql.jdbc.Driver";
    String user = "xxxxxxxxxxxx";
    String pass = "xxxxxxxxx";


    try
    {
    Class.forName(driver).newInstance();
    Connection con = (Connection)DriverManager.getConnection(url,user,p ass);
    System.out.println("Connected");
    Statement st=(Statement) con.createStatement();

    ResultSet rs1=(ResultSet) st.executeQuery("select count from path");
    if(rs1.next()){if(rs1.getInt(1)==0){a=0;}
    if(rs1.getInt(1)==1){a=1;}
    else{a=rs1.getInt(1);}


    st.executeUpdate("insert into path(idPath,HarborDestination,HarborDeparture,Pric e,Type,FinalPrice) values('"+a+"','"+jTextField2.getText()+"','"+jTex tField3.getText()+"','"+jTextField4.getText()+"',' "+jTextField5.getText()+"','"+jTextField6.getText( )+"')");
    System.out.println("1");
    }
    }
    catch(Exception e){
    System.out.println("Not Connected");
    }}


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Not seeing the result in the databse

    Please wrap your code with [code] tags so that it is easier to read, e.g.,
    [code]
    // your code here
    [/code]

    It preserves formatting, e.g.,
    // your code here

    You have
    catch(Exception e){
        System.out.println("Not Connected");
    }
    Printing "Not Connected" can be misleading because an exception may be thrown after a successful connection. Besides that, you'd always want to see the exception stack trace, so add e.printStackTrace() there. The problem you're facing may be due to an exception being thrown. If so, you can take a look at the stack trace to figure it out.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Not seeing the result in the databse

    I fixed it.
    Turned out that the error was from easyphp my admin
    i did it with workbench and it worked

Similar Threads

  1. write code for databse connect to mysql
    By viral.bhat in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 18th, 2014, 03:28 AM
  2. While for Databse Proplem
    By RSelvan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 26th, 2012, 02:02 AM
  3. sequnce from databse
    By nrao in forum JDBC & Databases
    Replies: 1
    Last Post: December 6th, 2010, 01:42 PM
  4. Insertion and select in JDBC for two different databse
    By nrao in forum JDBC & Databases
    Replies: 1
    Last Post: November 15th, 2010, 08:14 PM
  5. Insertion and select in JDBC for two different databse
    By nrao in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2010, 08:14 PM

Tags for this Thread