I made a simple chat app. It uses database, this is not efficient cause the client queries database every few sec. Any way, I achieved what i needed, There are good ways out there like polling and commet, I will implement those later. Please take time to read abt this, I have few probs with this.
1) Consider two users 100 and 101, When 100 sends a msg to 101, i am saving the id as 100_101 in DB
2) When 101 send back msg to 100 it is saved as 101_100 in DB.
3) I am able to get the messages in order.
Problem-
1) Users should keep tht particular window open.
I want popup to open when there is new message. How to achieve that.
2) When a user(100) is typing user(101) should see the text as "100 is typing" if 101 chat window with 100 is open only. This should not involve any database stuff.
Work I have done. I can send data to server when user(100) starts typing to server. How to send data, i.e how to push data to user(101).
My presnt code is below.
ajax
$.ajax( {
type : "POST",
data : "uName=" + uName +"&opName=" + opName + "&msg=" + msg + "&colorCode="
+ colorCode,
url : "<%= path %>/chat/SaveChat",
error : function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
},
success : function(data) {
// alert(data);
$("#chat-area").html(data);
document.getElementById('chat-area').scrollTop = document.getElementById('chat-area').scrollHeight;
}
});
Servlet
try {
String newline = System.getProperty("line.separator");
String uName = req.getParameter("uName");
String opName= req.getParameter("opName");
String msg = req.getParameter("msg");
String colorCode = req.getParameter("colorCode");
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String dat =dateFormat.format(date);
PreparedStatement ps = db.conn.prepareStatement("INSERT INTO chatmessage"
+ "(message,username,msgtime,colorselected) "
+ " VALUES(?,?,?,?)");
ps.setString(1,msg);
ps.setString(2,uName+"_"+opName);
ps.setString(3,dat);
ps.setString(4,colorCode);
ps.executeUpdate();
ps.close();
ps = db.conn.prepareStatement("select * from chatmessage where username=? or username=? order by id asc");
ps.setString(1,uName+"_"+opName);
ps.setString(2,opName+"_"+uName);
ResultSet rs=ps.executeQuery();
String temp[];
StringBuilder sb = new StringBuilder();
while(rs.next())
{
temp=rs.getString("username").split("_");
/* out.println(newline);
out.print(temp[0]+":");
out.print(rs.getString("message"));
out.println(newline);*/
sb.append("<span style='background:#"
+ rs.getString("colorselected") + "'>" + temp[0]
+ "</span>" + rs.getString("message") + "<br/><br/>");
}
db.conn.close();
out.print(replaceEmoticons(sb.toString()));
//out.print("success");
}
catch(Exception ce){
out.println("<font size='30' color='red'>Error Code 004</font>");
// RequestDispatcher rd = req.getRequestDispatcher("../status/error.jsp");
// rd.forward(req, res);
}finally{
try{
db.conn.close();
}catch(Exception e){}
}
Thankyou any easy and valid ideas are appreciated.
Related
i am a student and right now I'm doing an internship working with a local library, and in this case i have the following problem:
In the project i´m making, i need to retrieve image data from a temporal table, constructed in ORACLE that receives its data from some triggers in an INFORMIX DB and parse it through a monitor made in JAVA, in a JSON format to a web service published in C# and insert that image in a SQL Server DB.
I looked around and i found that it was possible to parse images through JSON using Base64 encoding and whatnot but when they talk about it they say that you must have the image path file and encode it. as you may have realized by now, i cant use that route because i don't have those images, best case scenario, the triggers are able to feed some BLOB data (by what I've been told). but i have to insert them in the SQL Server DB as Varbinary(MAX).
To summarize:
-->Informix DB has images -->triggers feed an ORACLE Temp_table (images sent probably as BLOB or CLOB at most)-->monitor made in JAVA must read those BLOBS or CLOBS and send them through JSON
-->Web Service made in C# must receive that JSON, and insert the images in a SQL Server DB (where they need to be visible, without having the physical file to refer to).
the schema i´m using (it has been IMPOSED to me, i didn't had a saying in this) is something similar to this: (it´s really long and tedious code so i´ll try to make it as neat and clean as possible)
This is the part of the java monitor that specifies which fields from the temp_table are feeding what fields in the JSON structure
public static BookRecordList viewBookRecordTable(Connection connection) throws ExceptionToOracleConcurrent
{
BookRecordList bookRecordList = new BookRecordList();
BookRecord bookRecord = new BookRecord();
Statement stmt = null;
String query = "SELECT operacion,"
+ "UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(img_logo,32670,1))"
+ "x_logo,"
+ "UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(img_logoGris,32760,1))"
+ "UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(r_firma,32670,1)),"
+ " FROM "
+ dataBaseConnectionData.getDB_SHCHEMA() + "."+ dataBaseConnectionData.getDB_TABLE_COLA()
+ " WHERE (some condition)";
try
{
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
try
{
bookRecord = new BookRecord();
bookRecord.setOperacion(rs.getInt("operacion"));
bookRecord.setImg_logo(rs.getString("img_logo"));
bookRecord.setImg_logoGris(rs.getString("img_logoGris"))
bookRecord.setR_firma(rs.getString("r_firma"));
bookRecord.print();
bookRecordList.getBookRecordList().add(bookRecord);
}
catch (Exception e)
{
logger.error("Some exception " + dataBaseConnectionData.getDB_TABLE_COLA() + ": " + e.toString());
e.printStackTrace();
//Process next order
continue;
}
}
}
catch (SQLException e )
{
logger.fatal("Some exception " + dataBaseConnectionData.getDB_TABLE_COLA() + ": " + e.toString());
throw new ExceptionToOracleConcurrent("exception definition " + dataBaseConnectionData.getDB_TABLE_COLA() + ": " + e.toString());
}
finally
{
if (stmt != null)
{
try
{
stmt.close();
}
catch (SQLException e)
{
logger.fatal("another exception " + e.toString());
}
}
}
return bookRecordList;
}
This is the part of the java monitor that generates the JSON (the empty cases contain another stuff that goes into the JSON but i sorted that out)
private static String GenerateJSON(SomeClass someClass) throws IOException
{
int operation = someClass.getOperation();
JSONObject obj = new JSONObject();
String jsonText = "";
switch (operation)
{
case 0:
//obligatory fields
obj.put("img_logo",someClass.getImg_logo());
break;
case 1:
break;
case 2:
//Obligatory fields
obj.put("img_foto",someClass.getC_empleado());
obj.put("img_firma",someClass.getC_empleado());
break;
case 3:
obj.put("r_firma",someClass.getR_firma());
break;
case 4:
break;
case 5:
break;
}
StringWriter out = new StringWriter();
obj.writeJSONString(out);
jsonText = out.toString();
String newJson = jsonText.replace("\\/", "/");
logger.info("JSON a enviar: " + newJson);
return newJson;
}
The web service is made in C#, it´s another case based program, structured accordingly to the operation number received in the JSON, it calls a number of function and, in the end, it comes down to these two:
this part of the WS receive the parameters of the parsed JSON
public int ActualizarFichaLibro( String img_foto, String r_firma)
{
try
{
//Define query to insert
Cmd.CommandText = QueryCFA.ActualizarFicha();
//Define parameters types to insert
Cmd.Parameters.Add("#img_foto", SqlDbType.VarBinary, -1);
Cmd.Parameters.Add("#r_firma", SqlDbType.VarBinary, -1);
//Define parameters values to insert
Cmd.Parameters["#img_foto"].Value = img_foto;
Cmd.Parameters["#r_firma"].Value = r_firma;
int rowCount = Cmd.ExecuteNonQuery();
CerrarConexionBd();
return rowCount;
}
catch (Exception)
{
return 0;
}
}
and finally that invokes a simple query, in this particular case, to this one:
public string ActualizarFicha()
{
Query = "UPDATE dbo.fichaEmpleado SET( CASE WHEN #img_foto = '' THEN NULL ELSE img_foto = CONVERT(VARBINARY(MAX), #img_foto, 2) END,"
+ "CASE WHEN #r_firma = '' THEN NULL ELSE img_firma = CONVERT(VARBINARY(MAX), #r_firma, 2) END,"
+"WHERE (some conditions)";
return Query;
}
my questions are:
is there a way to do this (sending images from one DB to anther) through JSON, specifically with this massive schema this people got going on? if not is there a way to do it?
the querys for reading a BLOB (possible BLOB) and inserting a Varbinary are well implemented?
I´m sorry for the extremely long explanation, I've been working on this for a week and i cant seem to find a proper way to do it (at least not with this schema, but the bosses don't want to change it)
I have created an ajax call in jquery to my server, the trouble I'm facing now is that my response is printing ? even though the correct integer value is written into the output stream. Ajax function is given below.
$dntb.on('click', 'button', function(event) {
var i = $(this).closest('tr').index(); //have to get the row where the button is clicked
var sditmId = $("#sditm").val();
var sdhedId = $("#sdhed").val();
$.get('getstock', {
sditmId: sditmId,
sdhedId: sdhedId
}, function(response) {
alert(response);
var stk = ""+response;
$("#stk").val(stk);
});
});
This function is called on click of an issue button in my table shown below
The server code is given below
int stk = null;
switch (userPath) {
case "/getstock":
stk = opo.getStockData(request.getParameter("sditmId") request.getParameter("sdhedId")); //value to write into the output stream.
break;
case "/temp":
//er = opo.checkCatUniqueForEdit(request.getParameter("catName"), request.getParameter("catId"));
break;
}
System.out.println(stk); //Printing correctly
response.setContentType("text/html");
response.getWriter().write(stk);
Code to get the value
public int getStockData(String sditm, String sdhed) {
int stk = 0;
try {
String query = "Select stk.Stk_instk from tbstk stk inner join tbsditm itm on itm.Sditm_prdid=stk.Stk_prdid where itm.Sditm_sdhed=" + sdhed + " and itm.Sditm_id=" + sditm;
Statement stmt = dcon.con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next()) {
stk = rs.getInt("Stk_instk");
}
} catch (SQLException ex) {
Logger.getLogger(Op_OrdConf.class.getName()).log(Level.SEVERE, null, ex);
}
return stk;
}
The ajax call happens successfully but when I alert the response I'm getting and I'm getting the value correctly in the server but in the client side it is ?. Please help me solve this
Not sure but seems that you are missing a comma here:
stk = opo.getStockData(request.getParameter("sditmId"), request.getParameter("sdhedId"));
//----------------------------------------------------^-----i think this is missing.
As per your comment i would suggest you to explicitly set the dataType to html:
$.get('getstock', {
sditmId: sditmId,
sdhedId: sdhedId
}, function(response) {
alert(response);
var stk = "" + response;
$("#stk").val(stk);
},"html"); //<----------add the dataType here.
I converted the int value returning from the function as given below to String, it seems to be some conflict between the content type and the value written into the output stream
stk = opo.getStockData(request.getParameter("sditmId") request.getParameter("sdhedId"));
I am trying to read IRC and pull data from individual IRC messages in Processing. You can see the code (also with twitter library, ignore that) and I need some pointers on how I can pull the data out in the format of Nick:Message so it can be displayed in a visualization.
//Twitter
import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;
// Import the net libraries
import processing.net.*;
// Declare a client
Client client;
Twitter twitter;
String searchString = "god";
List<Status> tweets;
String server = "irc.twitch.tv";
String nick = "NugShow";
//String user = "simple_bot";
int port = 6667;
String channel = "#nugshow";
String password = "xx";
String in = "butt";
String checkFor;
//bools
Boolean isLive = false;
int privMsgIndex;
int atIndex;
String playerSubstring;
// The channel which the bot will joString channel = "#irchacks";
int currentTweet;
void setup()
{
size(800,600);
frameRate(60);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("xx");
cb.setOAuthConsumerSecret("xx");
cb.setOAuthAccessToken("xx");
cb.setOAuthAccessTokenSecret("xx");
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
getNewTweets();
currentTweet = 0;
thread("refreshTweets");
thread("loopChat");
connectToServer();
//IRC
}
void draw()
{
if (client.available() > 0) {
String in = client.readString();
println(in);
}
if (isLive == false){
if (client.available() > 0) {
}
} else {
}
/*
fill(0, 40);
rect(0, 0, width, height);
currentTweet = currentTweet + 1;
if (currentTweet >= tweets.size())
{
currentTweet = 0;
}
Status status = tweets.get(currentTweet);
fill(200);
text(status.getText(), random(width), random(height), 300, 200);
delay(100);
*/
}
void joinChannel() {
String in = client.readString();
client.write( "JOIN " + channel + "\n\r" );
client.clear();
in = client.readString();
println(in);
if (in != null){
//println("Recieved data");
println(in);
//String inString = myClient.readStringUntil("");
isLive = true;
println(isLive);
}
}
void connectToServer()
{
client = new Client(this, server , 6667);
client.write( "PASS " + password + "\n\r" );
println(password + " sent!");
client.write( "NICK " + nick + "\n\r" );
println(nick + " sent!");
joinChannel();
}
void getNewTweets()
{
try
{
Query query = new Query(searchString);
QueryResult result = twitter.search(query);
tweets = result.getTweets();
}
catch (TwitterException te)
{
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
void refreshTweets()
{
while (true)
{
getNewTweets();
println("Updated Tweets");
delay(30000);
}
}
void loopChat()
{
while (true)
{
if (privMsgIndex != 0){
println(privMsgIndex);
//privMsgIndex = privMsgIndex - 15;
atIndex = in.indexOf("#");
println(atIndex);
//atIndex = atIndex + 1;
playerSubstring = in.substring(atIndex, privMsgIndex);
println(playerSubstring);
} else {
println("looped");
}
delay(300);
client.clear();
in = null;
}
}
void keyPressed()
{
}
void tweet()
{
try
{
Status status = twitter.updateStatus("This is a tweet sent from Processing!");
System.out.println("Status updated to [" + status.getText() + "].");
}
catch (TwitterException te)
{
System.out.println("Error: "+ te.getMessage());
}
}
The chat commands look like this: :nugshow!nugshow#nugshow.testserver.local PRIVMSG #nugshow :dddd where nugshow is the username, #nugshow is the channel, and dddd is the message. I need to get it into the format of nugshow: dddd.
there is a lot of header information that I'm not sure how to strip out of client.recieved buffer as well, it looks like this:
:testserver.local 001 nugshow :Welcome, GLHF!
:testserver.local 002 nugshow :Your host is testserver.local
:testserver.local 003 nugshow :This server is rather new
:testserver.local 004 nugshow :-
:testserver.local 375 nugshow :-
:testserver.local 372 nugshow :You are in a maze of twisty passages, all alike.
:testserver.local 376 nugshow :>
:nugshow!nugshow#nugshow.testserver.local JOIN #nugshow
:nugshow.testserver.local 353 nugshow = #nugshow :nugshow
:nugshow.testserver.local 366 nugshow #nugshow :End of /NAMES list
:jtv!jtv#jtv.testserver.local PRIVMSG nugshow :HISTORYEND nugshow
I would not recommend regex here. At least not if you want to be able to catch all types of IRC messages. The key is to look at the message code to know what you can actually get out of the message. As I'm also writing an IRC-client (just for giggles) I have some notes for you.
Be sure to answer any PINGs that the server sends you so you don't get kicked off. As the PING is sent with an identifier, you need to catch that and send it back. A simple way to do this is to check the last line that was sent from the server and substring it.
String line = inputStream.readLine();
if(line.substring(0,4).equals("PING")){
send("PONG " + line.substring(5)); // Assume you have some send-function.
}
This will make sure you don't get kicked off and can proceed to actually stay on a server.
As I mentioned, I do not recommend using regex for this as it would become a RegEx-of-doom. So, what I have done is to just split the line you get and put all the results in a String array.
String[] arr = line.split(" ");
As you know by your own message line you have posted, the IRC protocol separates things with spaces. So splitting at spaces in not all that shabby (we'll get how to deal with actual text in a bit).
The basic structure that is always the same (as far as I can tell) in messages is PREFIX COMMAND PARAM PARAM/TRAILING. So what does this mean? The PREFIX is where the message was sent from. Example ":user!user#host.com". The COMMAND is what the line actually is. You are looking for PRIVMSG here, but there are many, many, others that you might want to take care of. Like JOIN, PART, QUIT, 332 (current topic), 353 (nicks in channel, 404 (unable to send to channel), etc. etc. The PARAM and PARAM/TRAILING will all depend on the COMMAND.
So, what do we gain from splitting at spaces? This:
arr[0] = :user!user#host.com
arr[1] = COMMAND
arr[2] = PARAM
arr[3 onwards] = rest
We can now easily manage every command in it's own needed way.
Without further delay, lets get to your actual question, the PRIVMSG.
I will use this string: ":Chewtoy!chewtoy#stackoverflow.com PRIVMSG #stackoverflow :Ty: I saw your question and thought I should give you an answer."
After doing a split at the spaces, we get the array
arr[0] = :Chewtoy!chewtoy#stackoverflow.com
arr[1] = PRIVMSG
arr[2] = #stackoverflow
arr[3] = :Ty:
arr[4] = I
arr[5] = saw
...
As you can see, everything from 3 and onwards is the message you want. 0-2 is stuff that you need to be able to know who sent what where. My code for getting all this looks like this:
String[] arr = receivedLine.split(" ");
if(arr[1].equals("PRIVMSG")){
String[] usr = arr[0].split(!"); // Get the user, which is in usr[0]. Host in usr[1]
StringBuilder msg = new StringBuilder();
for(int i=3; i<arr.length; i++){ // We know the message starts at arr[3], so start counting from that.
msg.append(arr[i] + " ");
}
String chan = "";
if(arr[2].substring(0,1).equals("#")){ // We need to differentiate between sending to channel and sending a PM. The only difference in this is where the text is sent.
chan = arr[2];
} else{
chan = usr[0].substring(1); // substring(1) because we want Chewtoy, not :Chewtoy
}
// The result here will be:
// <#stackoverflow> Chewtoy: Ty: I saw your question and thought I should give you an answer.
sendItAllToWhereYouWantIt("<" + chan +"> " + usr[0].substring(1) + ": " + msg.substring(1));
}
Hope that helps.
I am really struggling with this problem. I am storing names and addresses of users as session variables on the server. In the else if statement, I want to search through previously entered names to match a name that is entered (with the address field blank), to the corresponding address that was entered for that name.
For example:
First entered details: Name=John, Address=Ireland,
Second entered details: Name=Mary, Address=France,
Third entered details: Name=John, Address=null,(EMPTY FIELD)
When these third details are entered for 'John', I want to retrieve the address for John (ie:Ireland) that was previously entered for that user. Can't figure out why it won't work. Any help is appreciated. Thanks
#WebServlet("/Test2") // tells server under which URL to offer this servlet
public class UserRegistration extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException {
// set content-type header before accessing the Writer
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// then write the response
out.println("<html>" + "<head><title>Online Shopping Directory</title></head>");
//Get the identifier of the book to display
out.println("<body bgcolor=\"#ffffff\">"
+ "<h2>Please enter your name:</h2>" + "<form method=\"get\">"
+ "<input type=\"text\" name=\"username\" size=\"25\">"
+ "<p></p>"
+ "<h2>Please enter your address:</h2>" + "<form method=\"get\">"
+ "<input type=\"text\" name=\"useraddress\" size=\"25\">"
+ "<p></p>"
+ "<input type=\"submit\" value=\"Submit\">"
+ "<input type=\"reset\" value=\"Reset\">"
+ "</form>");
String name = request.getParameter("username");
String address = request.getParameter("useraddress");
HttpSession session = request.getSession(true);
if ((name != null) && (name.length() > 0) && (address != null) && (address.length() > 0)) {
session.setAttribute("username", address);
out.println("The username " + name + " has been saved for "
+ "this session. The address of this user is "
+ (String) session.getAttribute("username"));
} else if ((name.equals("username")) && (address == null)) {
out.println("The username " + name + " is already saved. "
+ "The address of this user is "
+ (String) session.getAttribute("username"));
}
out.println("</body></html>");
out.close();
}
}
you have to do something like the following :
if ((name != null) && (name.length() > 0) ){
session.setAttribute("username", name);
out.println("The username " + name );
}else {
out.println("The username " + (String) session.getAttribute("username") );
}
if ((address != null) && (address.length() > 0)){
session.setAttribute("address", address);
out.println("The address " + adress );
}else {
out.println("The address " + (String) session.getAttribute("address") );
}
and please give me some feedback .
Hope That helps .
If you want a list to pop up, if the user enters a certain prefix to an already entered text, you have to store text first. Use a list object to add the information when it is submitted to the server and store it in the user's session. Keep in mind, that when the session times out or is removed, your list will not longer be available. To store the list of entered information in a more persistent manner, you could use a database instead.
When the user requests the page, where the information should be entered, you retrieve the list from her session and write it to the page (look for auto suggestion box to find out, how to do it using javascript).
You are actually creating a new session instance evertime, you should get the session instance associated with the request while you need to retrieve the attributes
Use request.getSession(false); this will return the associated session with the request or return null. you should be careful in handling sessions while managing sessions, that is when to create a new one or retrieve the session that had been created for the user
i have developed an app which executes sql jobs.
When I click on execute button the my application goes into running state and it halts untill the query is executed.
I want my app should not halt and the user should be able to enter other query and those query execution should run in background.
My question is how to run the execution of queries in background?
means when the execute button is clicked ,the remaining execution should run behind the screen.
My app is developed using struts1.3 framework.I have written the main functionality in execute() of Action Class
Code snippet of execute()
DAO dao1=new DAO();
System.out.println("Here...1");
con1=dao1.DBConnection(jndiname);
Statement st = con1.createStatement();
//status_id=1;
ResultSet rs = st.executeQuery(query);
System.out.println("Here...2");
String id = Long.toString(System.currentTimeMillis());
//int req_id = System.currentTimeMillis();
String dirTree= rsBundle.getString("CSV_DIR");
File f=new File(dirTree);
String[] directories = dirTree.split("/");
String[] lists=f.list();
for (String dir : directories )
{
if (!dir.isEmpty() )
{
if (f.exists())
{
System.out.println("directory exist");
}
if (!f.exists())
{
boolean success = (new File(dirTree).mkdirs());
if(success)
{
System.out.println("directory created");
}
}
}
}
for(String s:lists)
{
System.out.println("files.." + s);
}
String csv_file_path=dirTree+"/";
String csv_file_name=id +".csv";
//writing to csv file
CSVWriter writer = new CSVWriter(new FileWriter(csv_file_path + csv_file_name), ',',CSVWriter.NO_QUOTE_CHARACTER);
writer.writeAll(rs, true);
writer.close();
//status_id=7;
String zip_file_path=rsBundle.getString("zip_file_path");
String zip_filename=id + ".zip";
String zip_file_pwd=rsBundle.getString("zip_file_pwd");
//zip file creation
ZipUtil.zipDirWithPassword(dirTree, zip_file_path + zip_filename,zip_file_pwd);
String ftp_file_path=rsBundle.getString("ftp_file_path");
long zip_file_size= new File(zip_file_path + zip_filename).length();
System.out.println("File size..inside" + zip_file_size);
System.out.println("Here...3");
String exec_id=(String)request.getSession().getAttribute("userLoginId");
//int executor_id= Integer.parseInt(exec_id);
DateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
//get current date time with Date()
Date date = new Date();
System.out.println(dateFormat.format(date));
String query4 = "select executor_id,email_id from m_executor where windows_id = '" + exec_id + "'";
System.out.println("Query... " + query4);
//int i=0;
iPreparedStatement4=con.prepareStatement(query4);
iResultSet3=iPreparedStatement4.executeQuery();
while(iResultSet3.next())
{
//restriction=iResultSet2.getString(1);
exec_email=iResultSet3.getString(2);
executor_id=iResultSet3.getInt(1);
}
ValueListForExec db= new ValueListForExec();
String status_name="";
status_name=db.getStatusName(status_id);
if(zip_file_size <= 5242880){
System.out.println("send via email");
/*}
else
{*/
System.out.println("send via FTP");
upload.upload(host, usrname, pwd,zip_file_path + zip_filename, ftp_file_path,zip_filename);
}
String insertquery="{ call sp_process_job (?,?,?,?) }";
cs = con.prepareCall(insertquery.toString());
cs.setString(1,id);
cs.setString(2,host);
cs.setString(3,usrname);
cs.setString(4,pwd);
cs.execute();
con.commit();
You are about to enter the world of threading.
To run a task in the background you need to start that task on a separate thread.
If you are running in a Swing app you will need to ensure that you are not running the task on the event-dispatcher thread.
Have a look at SwingUtilities invokeLater.
You can use ExecutorService or Java Threads to do this job . You can write you sql job in Runnable/Callable object and once user click the button job should be given to other thread which will execute in background.Even you can use Thread Pool to transfer jobs to pooled thread.