Java, mysql, xml related problem.

H

hiisikukko

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();
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top