0

For a stand alone application to use database present remotely through internet, i heard the best option is a web service.

how can i first develop a web service and where should it place on?and i have a database and i should interact with the web service for selecting, deleting, inserting and updating data.

4
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by TheBuzzer
-1

thanx frnd.. yeah i hav learnt ASP.NET n c#.net bt i dont have an idea to solve my problem .. if u can help me plzz.

Votes + Comments
Drop the "text speak" and demonstrate some effort to solve your own problem before asking others to do it for you.
0

www.codeproject.com would be a great source for you to look at. They have a lot of tutorials on this topic. All it is, is an application which keeps running on the server where you database resides. It provides a collection of public methods which provide some sort of 'service' such as updating or deleting information in the database.

0

if u want to use java to interact to database doing commands I made a nice wrapper to make sql a bit eaiser for me doing basic stuff.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ottoclass;

import java.sql.*;
import java.util.*;
/**
 *
 * @author dlee
 */
public class SQLTable {

    private Vector<TreeMap> vectortable = new Vector<TreeMap>();
    private Connection myconnection;          


    public SQLTable() throws SQLException
    {
        try
        {
//            Driver mysqldriver = (Driver)Class.forName("org.gjt.mm.mysql.Driver").newInstance();
            myconnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + SharedData.DATABASE,SharedData.DATABASEUSERNAME,SharedData.DATABASEPASSWORD);
        }
        catch (SQLException e)
        {
            throw e;
        }
    }

    public Boolean makeTable(String sql) throws SQLException
    {
        Statement mystatement = myconnection.createStatement();
        ResultSet myresult = mystatement.executeQuery(sql);
        
        vectortable = new Vector<TreeMap>();
        int i = 0;
        
        try
        {
            while (myresult.next())
            {
                TreeMap table = new TreeMap();
                for (int j = 1; j <= myresult.getMetaData().getColumnCount(); j++)
                   table.put(myresult.getMetaData().getColumnLabel(j), myresult.getObject(j));
                
                vectortable.add(table);
                
                i++;
            }
        }
        catch (SQLException e)
        {
            throw e;
        }

        myresult.close();
        mystatement.close();
        return (i != 0);
    }
    
    public Vector<TreeMap> getTable()
    {
        return vectortable;
    }
    
    public TreeMap getRow()
    {
        return vectortable.get(0);
    }
    
    public Object getCell(String filename)
    {
       return vectortable.get(0).get(filename);
    }

    public Object getValue()
    {
        return vectortable.get(0).get(vectortable.get(0).firstKey());
    }
    
    public int insertRow(String table,TreeMap mykeys) throws SQLException
    {
        String query = "INSERT INTO `"+ table +"` (";

        Object mykey[] = mykeys.keySet().toArray();
        for (int i = 0; i < mykeys.size(); i++)
        {
            query += "`" + mykey[i] + "`,";
        }
        query = query.substring(0,query.length()-1);
        query += ") VALUES (";
        for (int i = 0; i < mykeys.size(); i++)
        {
            query += "?,";
        }
        query = query.substring(0,query.length()-1);
        query += ")";
        
        PreparedStatement mystatement = myconnection.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
        for (int i = 0; i < mykeys.size(); i++)
        {
            mystatement.setObject(i+1, mykeys.get(mykey[i]));
        }
        mystatement.execute();
        ResultSet myresult = mystatement.getGeneratedKeys();
        if (myresult.next())
        {
            int index = myresult.getInt(1);
            myresult.close();
            mystatement.close();
            return index;
        }
        else
            return -1;
    }
    
    public Boolean checkExist(String sql) throws SQLException
    {
        Statement mystatement = myconnection.createStatement();
        ResultSet myresult = mystatement.executeQuery(sql);
        return (myresult.next());
    }
    

    public void insertUpdateRow(String table,TreeMap mykeys, TreeMap myfilter) throws SQLException
    {
        String filterstring = "";
        Object myfilters[] = myfilter.keySet().toArray();
        for (int i = 0; i < myfilter.size(); i++)
        {
            filterstring += "`" + myfilters[i] + "` = '" + myfilter.get(myfilters[i]) + "' AND";
        }
        filterstring = filterstring.substring(0,filterstring.length()-3);
        
        if (checkExist("SELECT * FROM `" + table + "` WHERE " + filterstring))
        {
            String filler = "";
            Object keyset[] = mykeys.keySet().toArray();
            for (int i = 0; i < mykeys.size(); i ++)
            {
                filler += "`" + keyset[i] + "` = ?,";
            }
            filler = filler.substring(0,filler.length()-1);
            String update = "UPDATE `" + table + "` SET " + filler + " WHERE " + filterstring;
            PreparedStatement mystatement = myconnection.prepareStatement(update);
            for (int i = 0; i < mykeys.size(); i++)
            {
                mystatement.setObject(i+1, mykeys.get(keyset[i]));
            }
            mystatement.execute();
            mystatement.close();
        }
        else
        {
            insertRow(table, mykeys);
        }
    }    
    
    public void closeSQL() throws Exception
    {
        myconnection.close();
    }
    
    
}

This makes stuff database to java eaiser for me

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.