HELP PLZ URGENT Insert data in mysql database through java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashi1290
    New Member
    • Feb 2008
    • 6

    HELP PLZ URGENT Insert data in mysql database through java

    im getting exception message is null ... whwni print the stack trace its says something like this.......[Ljava.lang.Stac kTraceElement;@ 199939


    code is.......


    [CODE=Java] ResultSet rs;int i=-1;
    PreparedStateme nt ps;
    Class.forName(" com.mysql.jdbc. Driver");
    Connection con= DriverManager.g etConnection("j dbc:mysql://localhost:3306/abhi","root","r oot");
    String sql="INSERT INTO holiday (emp_id,holiday _type,start_dat e,no_of_days,re ason) VALUES(?,?,?,?, ?)";
    ps=con.prepareS tatement(sql);
    ps.setInt(1, upr.getEmpid()) ;
    ps.setString(2, "'"+upr.getHoli dayType()+"'");
    ps.setString(3, "'"+upr.getStar tDate()+"'");
    ps.setInt(4,upr .getNod());
    ps.setString(5, "'"+upr.getReas on()+"'");
    ps.close();
    con.close();
    try{
    i=ps.executeUpd ate();
    }
    catch(SQLExcept ion sqle)
    {
    System.out.prin tln("sql "+sqle.getMessa ge());
    }
    catch(Exception e)
    {
    System.out.prin tln("general in db insert "+e.getStackTra ce());
    }[/CODE]


    code does not insert any record but doest give any error also......... just exception
    Last edited by BigDaddyLH; Feb 20 '08, 04:59 PM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      To print out an exception, write:

      [CODE=Java]ex.printStackTr ace();[/CODE]

      One problem I see is that you are closing your statement and your connection before you execute the statement! Doesn't it make more sense to close your resources after you are done with them?

      Comment

      Working...