Java, mysql, xml related problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hiisikukko

    #1

    Java, mysql, xml related problem.

    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 cmgUpdateNormal Hours1_actionPe rformed(ActionE vent e) { ///button update
    if(e.getActionC ommand().equals ("Update"))
    {
    ResultSet Result;


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

    String sqlClause="sele ct count(*) from hours where days ='"+day+"'";
    Tietokantayhtey s Conn = new Tietokantayhtey s(); ///connection to the database
    Result= Conn.Query(sqlC lause);
    String result=null; //different result than Result

    try {
    Result.next();
    result=Result.g etString(1);
    } catch(Exception ex) {
    ex.printStackTr ace();
    }

    int tempa=Integer.p arseInt(result) ;
    if(tempa==1)
    {
    String sqlClause1 = "update hours set normalhours= '" + paivitus + "'" +
    "where proj_id = " + proj + " and days ='" + day + "'";
    tempa=Conn.Upda teQuery(sqlClau se1);
    }
    if(tempa==0)
    {
    String sqlClause2= "insert into hours (proj_id, days, normalhours) " +
    "values ("+proj+",'"+da y+"','"+paivitu s+"')";
    tempa=Conn.Upda teQuery(sqlClau se2);
    }


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


    And here is database connection class which i have created:

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

    package simple;


    import java.sql.*;

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



    public Tietokantayhtey s()
    {

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


    Conn = DriverManager.g etConnection
    ( "jdbc:odbc:pro" ,"root","");


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

    } catch (Exception e)

    {
    e.printStackTra ce();
    }

    }


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

    try {
    Result = st.executeQuery (sqlClause);

    } catch (Exception e)
    { e.printStackTra ce();
    }

    return Result;
    }


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



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

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

    } catch(Exception e)
    { e.printStackTra ce();
    }

    return muutoksia;
    }

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

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



    -------------------
    -
    hiisikukk
    -----------------------------------------------------------------------
    Posted via http://www.forum4designers.co
    -----------------------------------------------------------------------
    View this thread: http://www.forum4designers.com/message105717.htm

Working...