XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 9th, 2004, 05:50 AM
hiisikukko hiisikukko is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Finland
Posts: 6 hiisikukko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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();
	}
}
}


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Java, mysql, xml related problem.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT