
August 9th, 2004, 05:50 AM
|
|
Registered User
|
|
Join Date: Jul 2004
Location: Finland
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Java, mysql, xml related problem.
I have created project management software with Java and MySql and it works fine.
This applet gets and writes information directly to MySql database.
Problem is that those sqlClauses below(update and insert) should go "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 my code I would be very grateful.
My english is not so good, so my problem sentence could be little hard to understand, but please try. If it´s too hard to understand please tell me even how can i save results of those clauses to xml "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:odbc: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();
}
}
}
|