How To Create A Thread Sending Resultset Data To Database

Jul 18, 2014

I am very new to multithreading thus the code below reeks of ignorance,but i guess thats a place to start from.I am trying to obtain values that are already in my db and send them to a database by creating a new thread as follows:

//ADDED JUL 15 2014 12:07, LISTITEMS SO
public void getList() throws SQLException {
String sql = "select * from PRODUCTS";
out.print(m_Stmt);
ResultSet rs = m_Stmt.executeQuery(sql);
ExecutorService es=Executors.newCachedThreadPool();
es.execute(new Runnable(){
@Override

[code]...

View Replies


ADVERTISEMENT

JSP :: Online Quiz - Sending Resultset From Servlet

Mar 12, 2014

I am building an online quiz. I created a database , bean , controller and jsp. I connected database, wrote query , put resultset in arraylist of object and passed it to jsp. My program runs but arraylist size increases everytime and same question get displayed repeatedly . i cant find the error. Everytime i run the program arraylist size increases. I think it is adding same rows again ang again. here is my code for controller and jsp.

servlet code:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

[Code] .....

View Replies View Related

Servlets :: Multipart Form Data - Sending Additional Data?

Feb 21, 2014

I am using apache-commons-fileupload to get file from client to the server.(using JSP and Servlet).

JSP/HTML

<form method="POST" action="GetFile" enctype="multipart/form-data">
<input type="file" name="datafile">
<input type="text" name="text1">
<input type="submit" value="Next">
</form>

Servlet: GetFile

System.out.println(request.getParameter("text1"));

I am able to upload the file to the server, but I am not able to get the value of text1 in the servlet (I am getting null value of text1 in the servlet), I need this textfield in the form to submit some additional information while uploading it to the server.

--> Is enctype="multipart/form-data" option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additional textfield to the server.

--> Or is there any other problem in my code?

View Replies View Related

How To Store ResultSet To Other Data Structures

Oct 28, 2014

I have a java query like this

query ="Select major_career.Major_Title, career.ISCOTitle,career.FS.... " //only partial,
// I swear the query is correct
resultSet = statement.executeQuery(query); //this executes it
relArr = new ArrayList<String>(); //don't worry it is intialized

In the code below I tried to store the resultset components into the arraylist

int j = 1;
while (resultSet.next()) {
while(j<=numberOfColumns){
relArr.add(resultSet.getObject(j).toString());
j++;
}
} // end while

I am not sure whether the arraylist is able to store the result set because when i try to display it like show below it only shows some rows and only the first column

Iterator it = relArr.iterator();
while (it.hasNext())
{
System.out.println(it.next());

I want to manipulate the resultset results in my program by copying the resultset values to other datastructures.

View Replies View Related

JSP :: Retrieve Resultset Data From Listbox

Apr 2, 2014

I have retrieve the data in listbox from my database already and now again i want to select the data from this listbox and query on it , is it possible?

For Ex i have listbox as follows

<h4>Models For Selected Pattern:</h4>
</br>
<select Name="drop_model" multiple="true">
<%

try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url,username,userPassword);
Statement stmt = conn.createStatement();

[Code] ....

In this listbox some values are retrieved from database as

<option value="xyz">xyz</option>
<option value="pqr">pqr</option>
<option value="abc">abc</option>
<option value="lmn">lmn</option>

I want to select this values from listbox and query on them....

View Replies View Related

JDBC :: Resultset Data Processing - Default Fetchsize Returned

Jan 21, 2015

I have observed a strange behaviour from Resultset object. My application fetches 400 records from a table and processes these records every 10secs. By default the resultset has a fetchsize of 10 from the database cursor. As I understand if the query returns 400records, the resultset will fetch 40times, in multiple of 10 to get all these 400 records from database cursor.

Query : SELECT * FROM ( SELECT * FROM TestTable
WHERE STATE_ACTION = 0 ORDER BY ROP_TIME DESC )
WHERE ROWNUM <= 250

Observation : Under a normal operation, the resultset fetches all the 400 records on query execution from database cursor, but under unknown conditions the same resultset object fetches only 10 records from the database cursor and exits. Please refer page 297 in document below for the result fetch size details. JDBC developer guide for oracle 10g : [URL] .... This condition self-heals itself in few hours or restarting the database or restarting the server. The root cause of this behavior is unknown.

View Replies View Related

Servlets :: Sending A List Fetch From Database To JSP

Oct 6, 2014

I am trying to display a list fetched from DB in a JSP.

My servlet mapping is:

<servlet>
<description></description>
<display-name>DocumentsServlet</display-name>
<servlet-name>DocumentsServlet</servlet-name>
<servlet-class>com.xyz.servlet.DocumentsServlet</servlet-class>

[Code] ...

The code in the servlet is:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Doc> docs = null;
Connection con = null;

[Code] ....

The code in JSP is:

<%
List<WWDoc> completedDocsList = (List)request.getAttribute("completedDocs");
System.out.println("In JSP == "+completedDocsList.size());
%>

The request is not coming back to the JSP page.

If I change the servlet and have "request.getRequestDispatcher("/pages/ViewCompletedWWDocs.jsp").forward(request, response);" un commented, I get exception "java.lang.IllegalStateException: Cannot forward a response that is already committed".

View Replies View Related

Basics Of Controlling A Thread That Selects Data From MySQL

Nov 28, 2014

Lets say I am selecting a record at a time from mysql.

String sql = "SELECT id, first, last, age FROM Registration";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");

[Code] ....

The code above selects the data that i need.Now,i want to have this in some sort of a thread.This is what i want to achieve.

The code displays a record a time,i want to introduce sleep for 10 seconds before displaying the next record.Before going to the next record,i want the program to check whether a condition is true such as the value of a field of a table being 1 or 0.

If the condition is not true(therefore is false),i want the program to display 'waiting.....' and should continue waiting until the condition is true.

View Replies View Related

JavaFX 2.0 :: How To Create Off Screen Images By Canvas In Multi-thread Environment

Feb 25, 2015

I want to create off-screen images by Canvases in multi-thread environment.
 
I know that I use methods of GraphicsContext2D to draw on Canvas. Can I do this on Canvas which is not added to Scene ?
 
How can I get an image from a canvas after I invoke GraphicsContext2D methods? Can I get images in multi-thread environment ?

View Replies View Related

Sending To All Vs Sending To One Person In Server / Client Program

Apr 17, 2014

I have two programs that I'll post below, one is a Server and the other is a Client. The ChatServer runs once and many clients can run ChatClient from separate computers and talk together in their GUI's. The the client program comes with two buttons, one that's simulates the sending of a message to a single user ; "Send Message To User", and one that just generally sends a message ; "Send Message To All". Although now the Clients on the server seem to be able to selectively send messages to an individual by giving the recipient name, all the clients can see that message, which is not exact what I am aiming for. What I am going for is having the "Send Message To User" button click to send a message to the named user without all other users seeing the message.

The Server Program Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

[Code] ....

Now I have tried thing like having various input output streams and trying to connect those, but no luck. Tried fiddling with having the names arraylist directing the messages to one client versus all but that did not work out either. How I what I would need to do to go about doing this?

View Replies View Related

Swing/AWT/SWT :: What Is Event-dispatching Thread For GUIs And Why Use It Over Main Thread

Sep 20, 2014

I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
new SwingDemo();
}

I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { //why do this instead?
public void run(){
new SwingDemo();
}
});
}
}

Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?

View Replies View Related

Passing 2 Sub Arrays Into Sorting Thread Then To A 3rd Thread Merge

Oct 17, 2014

im having an issue with the 3rd thread that are supposed to merge the two sorted sub arrays , i pass the 2 subarrays to my runnable function sortlist and they are renamed IntSortList 1 and 2 and th1.start() and th1.join() are called and it works fine, but then i have another runnable constructor that takes IntSortList 1 and 2 but it does take a runnable. below is the code in my main,

Runnable InSortlist1 = new sortList(data2p1);
Runnable InSortlist1 = new sortList(data2p1);
Thread th1 = new Thread (IntSortlist1);
Thread th2 = new Thread (IntSortlist2);
try
{
th1.start();
th1.join();

[code]....

View Replies View Related

Accessing A Variable Of A Thread From Another Thread

Jul 16, 2014

class A extends Thread
{
String str;

public void run( )
{
//random stuff
}
}

[Code]....

View Replies View Related

Create JDialog Showing Database?

Jan 30, 2015

We are asked to create a JDialog showing our database. I am able to show the database but i can't seem to position the heading panel, table and back button. My back button is also not showing up. Here is part of my code...

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.sql.*;
import javax.swing.*;

[Code] ....

View Replies View Related

How To Create A New Java Class For Database Connection

Jan 15, 2015

I have a shop and I use visual studio.net to create an Inventory application to manage my shop. So I am familiar with vb.net codes.

Now, I'm trying to built another Inventory application for my shop using java, 'coz now I'm using Linux Ubuntu for my OS desktop and there's no visual studio.net in linux.

So in vb.net, there's a module that I use for database connection that I can call from any form that I needed.

I searched google for the equivalent module for java and there is none. But, there's an example that use a new java class.

Here's the code in MySQLConnect.java :

Java Code:

public class MySQLConnect {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/dbInventory";
static final String USER = "root";
static final String PASS = "root";
public static Connection ConnectDb() {

[Code] ....

View Replies View Related

Why Data Is Not Inserted Into Database

Dec 13, 2014

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

[Code] .....

View Replies View Related

Unable To Create A Connection In JSP Program To MSSQL Database

Oct 7, 2014

i have a problem in connecting my jsp program in MSsql 2005 i want to create a connection in my jsp program to MSsql database but theres an error of my work here is my code

Code:

PHP Code:

<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%@ page import="java.sql.*;" %>
<%@ page import="java.util.Enumeration;" %>
<html>
<head><title>Sample MS connection</title></head>

[Code]...

View Replies View Related

Create A Database Configuration File And Include All Other Files

Apr 19, 2014

I am creating an application in core java where i am using database. I need to create a database configuration file & include it all other files. So, how can i do that ?

Java Code:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:MYDSN","system","tiger"); mh_sh_highlight_all('java');

I cannot do this in an interface since only abstract methods exist there. I tried to create an another class file to extend it but my program is already extending other class i.e. javax.swing.JFrame..How can i implement this ? just by creating the object of that class in main method ?

View Replies View Related

Data From Database Is Not Showing On Combobox

Sep 17, 2014

Whats wrong with my code? The data from my database is not showing on my combo box.. I am trying to get my data in my database to my combo box ..

Here is my Code :

private void Fillcombo(){
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "purchasedb";
String driver = "com.mysql.jdbc.Driver";
String user = "root";

[Code] ....

View Replies View Related

Servlets :: Insert Data To The Database?

Apr 4, 2014

i am stucked with a little error in servlets

this is my jsp page
form.jsp
<form action="InsertData" method="post" >
username:<input type="text" name="username">
Password :<input type="password" name="password">

[Code]....

i am getting wroor page not foung 404

View Replies View Related

Servlets :: Data Is Not Getting Inserted Into Database

Mar 26, 2015

I am trying to insert data using servlet but it is not getting into database.

I have a two JSP's form from which i enter the data and using servelt trying to insert the data into database.

JSP page code:

1.add_question_list.jsp
<script language="JavaScript">
function validate(form) {
if (form.question.value == "") {

[code]...

View Replies View Related

Runnable Jar Does Not Show Data From Database

Mar 13, 2014

I am still working on my java course and now we have to create a jar file from a previous project (this is a project where a connection to the database is made and data is shown in a frame).

When I follow the instruction in my course material I don't get it to work. I've tried the following:

1. Open eclipse on windows xp
2. Right click on the project folder in eclipse
3. Click on "export" in the menu that appears
4. Choose "runnable jar"
5. click next
6. I insert the following parameters:

- Launch configuration --> I select my main class
- export destination --> I select the folder D:
- library handling --> Package required libraries into generated jar

7. click Finish

This is what happens when I dbl click the jarfile (wampserver is running):

1. I get an error: "SQL ERROR: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."

2. I click ok on the message and the following message appears: "SQL Error: null"

3. I click ok on this message and the frame with the fields appears without data from the database.

This is a crosspost to: [URL] ...

View Replies View Related

Servlets :: Insert Data To Database?

Aug 2, 2014

How can we insert data through java servlet?

I can insert data to table by using JSP Scriptlet easily but I have a hard time with servlet.

public class UsertToDatabase() {
public boolean inserUser(String name, String email, String pwd) throws SQLException {
PreparedStatement pstmt = null;
boolean flag = false;
System.out.println("start");
openConn();
System.out.println("start_1");
if(conn == null) {

[code]....

I am positive that the above code function fine. The problem is whenever I call UserToDB() class inside the servlet, and I got this error: java.lang.ClassNotFoundException: org.postgresql.

Driver which mean that my conn (connection) is not connected to the database but I have ensure to do so by calling openConn() before start the transaction.

This is my servlet code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String email = request.getParameter("email");
String password = request.getParameter("password");
List<String> errList = new ArrayList<String>();

[code]....

View Replies View Related

EJB / EE :: Caching Objects - Get Data From Database

Apr 29, 2014

How do we cache objects in EJB 2.

My requirement is i need to get data from the database for the first time and retain in cache it throughout the application life.

View Replies View Related

Transferring Data To MySQL Database

Jul 27, 2014

try {
is = new FileInputStream(file);
data = new byte[(int) file.length()];
is.read(data);
String extension = "";
int i = file.getName().lastIndexOf('.');
if(i>0)

[Code] ....

Everything works except transferring the image file.

View Replies View Related

Data From Database Not Showing On Combobox

Sep 17, 2014

Whats wrong with my code? the data from my database is not showing on my combo box.. I am trying to get my data in my database to my combo box ..

Here is my Code :

private void Fillcombo(){
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "purchasedb";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass= "ajleal";

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved