Java, mysql, xml related problem.

Discussion in 'XML' started by hiisikukko, Aug 9, 2004.

  1. hiisikukko

    hiisikukko Guest

    I have created project management software with Java and MySql and i
    works fine.
    This applet gets and writes information directly to MySql database.

    Problem is that those sqlClauses below(update and insert) should g
    "through" xml "document" and i haven´t got idea how to do that.
    If someone could give me advices or even tell me how I must modify m
    code I would be very grateful.

    My english is not so good, so my problem sentence could be little har
    to understand, but please try. If it´s too hard to understand pleas
    tell me even how can i save results of those clauses to xm
    "document".

    Here is part of main program:
    Code
    -------------------

    void cmgUpdateNormalHours1_actionPerformed(ActionEvent e) { ///button update
    if(e.getActionCommand().equals("Update"))
    {
    ResultSet Result;


    String proj= txtProjectNumber.getText();//gets project number
    String day= txtDate1.getText();//gets date
    String paivitus = txtNormalHours1.getText(); //gets normalhours
    int changes=0;

    String sqlClause="select count(*) from hours where days ='"+day+"'";
    Tietokantayhteys Conn = new Tietokantayhteys(); ///connection to the database
    Result= Conn.Query(sqlClause);
    String result=null; //different result than Result

    try {
    Result.next();
    result=Result.getString(1);
    } catch(Exception ex) {
    ex.printStackTrace();
    }

    int tempa=Integer.parseInt(result);
    if(tempa==1)
    {
    String sqlClause1 = "update hours set normalhours= '" + paivitus + "'" +
    "where proj_id = " + proj + " and days ='" + day + "'";
    tempa=Conn.UpdateQuery(sqlClause1);
    }
    if(tempa==0)
    {
    String sqlClause2= "insert into hours (proj_id, days, normalhours) " +
    "values ("+proj+",'"+day+"','"+paivitus+"')";
    tempa=Conn.UpdateQuery(sqlClause2);
    }


    -------------------


    And here is database connection class which i have created:

    Code
    -------------------

    package simple;


    import java.sql.*;

    public class Tietokantayhteys
    {
    ///määritellään luokan tarvitsemat oliot
    ///define object which class need
    Connection Conn;
    Statement st;
    ResultSet Result;



    public Tietokantayhteys()
    {

    //open connection to database
    try
    {
    ///load database driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


    Conn = DriverManager.getConnection
    ( "jdbc:eek:dbc:pro","root","");


    //set start value to Statement object
    st = Conn.createStatement();

    } catch (Exception e)

    {
    e.printStackTrace();
    }

    }


    // query method for select
    public ResultSet Query(String sqlClause)
    {

    try {
    Result = st.executeQuery(sqlClause);

    } catch (Exception e)
    { e.printStackTrace();
    }

    return Result;
    }


    /// update method for update inquery
    public int UpdateQuery(String sqlClause)
    {



    //saves how many changes has been made
    int muutoksia=0;

    try {
    muutoksia = st.executeUpdate(sqlClause); ///<---muutoksia means == changes

    } catch(Exception e)
    { e.printStackTrace();
    }

    return muutoksia;
    }

    ////close all connections
    public void suljeYhteys() ///<---means close connection
    {
    try {

    st.close();
    Conn.close();
    } catch(Exception e)
    { e.printStackTrace();
    }
    }
    }



    -------------------
    -
    hiisikukk
    -----------------------------------------------------------------------
    Posted via http://www.forum4designers.co
    -----------------------------------------------------------------------
    View this thread: http://www.forum4designers.com/message105717.htm
     
    hiisikukko, Aug 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JL
    Replies:
    0
    Views:
    1,152
  2. Ken
    Replies:
    4
    Views:
    2,784
    Eric Sosman
    Jun 21, 2004
  3. Ravi
    Replies:
    6
    Views:
    1,414
    Suchandra Thapa
    Jul 21, 2003
  4. Maxwell Hammer
    Replies:
    7
    Views:
    650
    Peter Hansen
    Jun 18, 2005
  5. Roedy Green
    Replies:
    0
    Views:
    1,479
    Roedy Green
    Jul 23, 2009
Loading...

Share This Page