Console SQL Query App Not Working Correctly

Nov 6, 2014

My console SQL Query app is not giving me the desired output.I am sure its might have something to do with my SQL Query.Its missing the description of the stock items and it prints a new line for each user as per number of stocks an repeats the user details and then prints the stock listed by that user(only want the user listed once with all its stocks). I will add my files and current output and desired out put below.

MakeDB.java:

import java.sql.*;
import java.io.*;
public class MakeDB
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:StockTracker";

[Code] .....

View Replies


ADVERTISEMENT

Java Console SQL DB Query App

Nov 4, 2014

I seem to be having a issue with my java console app what it should do is query a SQL DB and list the user details (userid, firstname ,lastname) from the user table, and the users stocks (stockname ,stockdiscription) associated to each user from the userstocks table if I'm thinking correctly!

I'm sure it is just a logical error, but I'm not sure of the way to get the out put I'm looking for. I will add the makeDB.java file and DatabaseQuery.java file as well as the current Exception(Run Time Exception) below.

**I have added other users and stocks manually - Not just what the MakeDB.java file inserts **

Output and Exception:

Stock holdings by User
User ID User Name
Stock - Description
-------------------------------------------
admin01 Default Admin
Exception in thread "main" java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(JdbcOdbcResultSet.java:6647
)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(JdbcOdbcResultSet.java:1248)
at DatabaseQuery.main(DatabaseQuery.java:45)
Press any key to continue . . .

Java Code:

MakeDB.java:
import java.sql.*;
import java.io.*;
public class MakeDB
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

[Code] ....

View Replies View Related

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

GCanvas In ACM Graphics Not Working Correctly

Mar 25, 2014

I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:

import acm.graphics.GCanvas;
public class Grid extends GCanvas{
private final static int WIDTH = 300;
private final static int HEIGHT = 300;
private final int DIMENSION = 5;
Cell[][] grid;

[code]....

View Replies View Related

JSP :: Java Server Sent Events Not Working Correctly

Oct 10, 2014

Code structure :

Server : Java Servlet
Client : Simple JSP
Communication : Server Sent Events every 1 second
Here is the problem.

My code needed the server to send updates every one second to the client as stated above. Hence, I added a while loop with a sleep of 1000 milliseconds in the servlet code as shown below. The following strange behavior is observed:

- While the server is sending updates to the client, and the client window closes by mistake, the server does not stop sending updates It continues sending the data.
- When the client is re-opened, it sends data much faster (almost double). For example, the server sends 60 seconds worth of updates (60 updates) in just 25-30 seconds. The server sends faster updates not only for this round of updates, but also for any subsequent updates.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter writer = null;
try{

[Code]......

This server behavior is much unexpected. Am I writing the server side code wrong? I have looked around a lot and only found while loop method for modifying the server update interval. Is there any other method which I am missing?

View Replies View Related

Counting Repeated Instances - Parallel Array Is Not Working Correctly

Sep 6, 2014

So in my parallel array i read from a textfile of strings and if i enter the string into the string array and if strings are repeated i store it in a parallel array that counts repeated instances. I'm supposed to get 27 15 21 23 20 but instead i get 106 0 0 0 0....

Scanner sc=new Scanner(new File("Cat.txt"));
String category=sc.nextLine();
int total=sc.nextInt();
int[]totcat=new int[total];
String[]names=new String[total];
while(sc.hasNextLine()){

[Code] .....

View Replies View Related

Console Freezes When Working In Different Threads

Jul 22, 2014

I have a console application. One thread allows a user to directly input into a console. Another thread listens on a tcp port, takes input, processes it, and then writes it to the console. The work in different threads, but in tcp thread, one I call a method outside that thread that writes to console, it often gets stuck. here is a mockup of situation:

Java Code:

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

[Code] ......

It often freezes on "Attempt 1". Before I used System.out there, I also tried console.writer() there but both freeze at that point often. Any situation where console or System.out.writeln freeze when working across threads and why it is occurring? It almost feels like one thread has locked the console so the others can't write to it.

View Replies View Related

PreparedStatement For MySQL Query - Where Query Seems To Get Cut Off

Mar 21, 2014

I am having a problem with a PreparedStatement for a MySQL query, where the query seems to get cut off. I can't really post a self contained example, because it involves an SQL database.The part of the code with the problem...

Java Code:

public void insertEntry(
Hashtable<String, String> strings,
Hashtable<String, Integer> integers,
Date created, Date paid, boolean enabled)
throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");

[code]....

The output of the whole program, though all it has done so far is create some default values and attempt to insert them with the above code, where the problem occurs.

Debug: SQLpaid = 1990-03-21

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT enabled=0, username='default_username', created='2000-03-21', paid='1990-' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:45)

[code]....

View Replies View Related

JSP :: Query String URL

Apr 10, 2014

how this query string will be prnted it is not showing me the psid values.

<tr bgcolor="pink" >
<td><%=resultSet.getString("FirstName") %></td>
<td><%=resultSet.getString("LastName") %></td>
<td><%=resultSet.getString("Username") %></td>
<td><%=resultSet.getString("Password") %></td>
<td><%=resultSet.getInt("Psid")%></td>
<td><a href="Edit.jsp?psid="<%=resultSet.getInt("Psid")%>>Edit</a></td>
<td><a href="Delete.jsp">Delete</a></td>
</tr>

View Replies View Related

JSP :: Sorting Query In JSTL?

Jun 21, 2006

i am doing a code using JSTL to fire a query. everything come fine except the resule is not sorted as desired. i am putting the code below--

String sort_order=(String)request.getAttribute("sort_order");
request.setAttribute("sort_order",sort_order);
<sql:query var="viewQueryj" sql= "select USER_ID, PERMISSION_ID, USER_NAME from administrator order by ?">
<sql:param value="${sort_order}"/>
</sql:query>

now the resule is always sorted by USER_ID. if i want to sort it using USER_NAME i pass parameter from controller to this page in sort_oredr variable which comes fine but the result doesn't sort by name, only by id. if i hardcode USER_NAME in query then the result is as desired.

View Replies View Related

JSP :: Insert Into Table Query

Feb 18, 2014

i found some problem for this jsp code. Actually I'm new in jsp. I'm trying to insert some data in a sql table in jsp by user input. Here's my code but i couldn't completed it.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

[Code] ....

View Replies View Related

Using A Database Query Result

Nov 17, 2014

I have done 90% of the coding however i am stuck with producing the output, i just cant get the user fields to show.

I have attached a picture of the output that is required. The program consists of two classes i have attached the database class, and have inserted my coding below.

import java.sql.*;
import java.io.*;
import java.util.*;
public class QueryDB {
private Connection con = null;
String userID,

[Code] ...

Attached image(s)

View Replies View Related

Using Database Query Result

Nov 20, 2014

I have to get my output to show as per the image attached i am very close but not there yet. I have also attached the database where i extract my information from

/*
Program Name: QueryDBDB.java
Purpose: to build an initial database for the stocktrakcer application
*/

import java.sql.*;
import java.io.*;
import java.util.*;
public class QueryDB
{
private Connection con = null;
String userID,firstName,lastName,name,symbol;
public QueryDB() throws Exception

[Code] .....

Attached image(s)

View Replies View Related

How To Populate Jcombobox From MySQL Query

Sep 13, 2014

How could i populate jcombobox2 from MySQL depending upon the value of jcombobox1??

View Replies View Related

Stock Database Query Class

Dec 14, 2014

I have a Stock Database query class, it compiles and runs well. Thing is when i enter a user, it shows a user stock information but it repeats showing the same user in the command prompt. the repetition is so fast, you can't see the information. All i wanted was the application to show a user's info, then asks you to enter another user again and so forth. Here is the code

import java.io.*;
import java.sql.*;
import java.util.*;
public class StockDatabaseQuery {
public static void main(String[] args)throws Exception {
String userID;
String firstName;

[Code] ....

View Replies View Related

Dynamic SQL In Java - Query Value From Database

Jun 18, 2014

I have code which query value from database, the use case is the user can enter value as 1,01,11 in database but when the user enter value in xml file he can only enter 11,01,12 in database there is two columns lets say column test1=1 and test2=2 combination of this is 12, which is the value the use will enter in xml, but sometime the use can enter test1=04 than column test2=00 how can i approach this
 
I got table called card with column crdind,crdpos1,cardpos2 as primary key. The user can enter value as
 
crdind=1
crdpos1=5
crdpos2=3
inactivedate=2013-05-24
activedate=null
 
another row
 
crdind=1
crdpos1=5
crdpos2=5
inactivedate=2013-05-24
activedate=null
 
another row

crdind=6
crdpos1=02
crdpos2=00
inactivedate=2013-05-24
activedate=null
 
The rule say if you enter one number in crdpos1 eg 2 than you must enter value in crdpos2 it can be any number 1-9 but if you enter 00-09 in crdpos1 than crdpos2 is 00
 
The challenge I have is to query this value after they been enter. I have xml file which got field crdpos the use enter 15 which is the combination of column crdpos1=1 and crdpos2=5 ... How can I split the value crdpos and got and able to query in database in two separate column ....

View Replies View Related

Project Is Working On JFrame - But Not Working On JApplet

Apr 10, 2014

I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,

1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.

2) The problem may be to display the JDesktopPane or JInternalFrame.

My working Server Code extends withe JFrame..Java Code:

package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

JSP :: Assigning Session Variable In Query Syntax

Jan 9, 2015

In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:

<sql:query dataSource="${user}" var="result">
SELECT * from users where email = ${sessionScope.email};
</sql:query>

It doesn't work.

View Replies View Related

Query About Use Of NextLine Method Of Scanner Class

Apr 10, 2014

My code is as follows:

import java.util.Scanner;
public class GetUserInput {
public static void main (String args[]) {
int i;
float f ;
String s;

[code]....

My Query is: input.nextLine() does not wait for user input. Instead it continues execution from next line. But if I move up input.nextLine(); before both input.nextInt(); and input.nextFloat() in the above code, the execution works fine, input.nextLine(); waits for user input. edited code and output are as follows.

import java.util.Scanner;
public class GetUserInput {
public static void main (String args[]) {
int i;
float f ;
String s;

[code]....

View Replies View Related

How To Get Desired Output Layout Database Query

Jan 15, 2015

My output of my app its outputting the correct data just no the format ...

code :

DatabaseQuery.java :
import java.io.*;
import java.sql.*;
import java.util.*;
public class DatabaseQuery

[Code] ....

Current output:

Stock holdings by User

User ID User Name
Stock - Description
-------------------------------------------
admin01
Default Admin
DELL Dell Computer Corp
admin01
Default Admin
MSFT Microsoft Computer Corp

[Code] ....

Desired Output :

Stock holdings by User

User ID User Name
Stock - Description
-------------------------------------------
admin01 Default Admin
DELL Dell Computer Corp
MSFT Microsoft Computer Corp
ORCL Oracle Corp

[Code] .....

View Replies View Related

Show Count Mysql Query Into JTextField?

Dec 5, 2014

I want to show the number of rows that is available in the table from my MySQL table. The thing is, im doing a music system database thingy and i want to show how much songs there is in the database in my GUI ie through a jTextField.

View Replies View Related

How To Store SQL Query In Tree Format In XML File

Nov 30, 2014

I want to store sql query in tree format in xml file.I wrote a code which split the code into different tokens and store it in xml file.I am storing keywords like "select",from,where etc as xmlelements and the values of these keywords as textnodes inside corresponding elements.When the query contains single single statement it works as i need.but when nested query occurs i want to store the nested query inside "where" element.In that case the code didn't works properly.I am hereby attaching the code. When i try to store the xmldata in "CreateFiles.xml" file ,the file is not displaying in the corresponding folder.what is the reason for that?

CreateXml.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package querywork;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;

[Code]...

View Replies View Related

Query Embed In JAVA Returns NULL

Oct 4, 2014

I have embed a query in the JAVA to retrieve the data from the back end and I use Oracle for back end. What I'm trying to do is in my query has been shown below. The issue here is that result set returns the NULL. But fine when I change the query "SELECT 5 FROM DUAL" and it returns 5 for me which right. When I try to run the same at the back end as a query I'm getting proper result.
 
public String getReturnPart(String partNumberIn) {
//int returnPartNumber = 0;
  String query =
"SELECT COUNT(*) AS CHECK1 FROM PART_MASTER PM,UNITS_OF_MEASURE UOM WHERE PM.PART_NUMBER = '" +  partNumberIn
  + "' AND PM.UNIT_OF_ISSUE = UOM.UNIT_OF_MEASURE AND UOM.UNIT_TYPE = 0 ";
  //String query = "SELECT 5 AS CHECK1  FROM DUAL"; This returns fine as "5"
  ResultSet result = null;

[Code] ....

View Replies View Related

JSF :: Passing Selected Hyperlink Value As Where Clause Argument In Query

Dec 28, 2013

I have a mySql table of PROJECTS, which I am displaying as a list in the index.xhtml. The projectid column contains hyperlinks. When they're clicked I would like the specific projectid row selected to be passed as the query argument into another jsf file (ListProjects.xhtml) which displays all the project values referring to the projectid selected in the index.xhtml. The named query is:

@NamedQuery(name = "Projects.findByProjectid", query = "SELECT p FROM Projects p WHERE p.projectid = :projectid")
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

[Code] ....

I get the following stack trace. How to correctly pass the hyperlink parameters.

org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke public void com.manaar.beans.SelProjectMgtBean.init() on com.manaar.beans.SelProjectMgtBean@681859ae
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:91)

[Code] ....

View Replies View Related

JSF :: Escape Characters Of Primefaces Editor To Do A Query On Sparql

Sep 25, 2014

How do I escape the characters of a primefaces editor?

I have this in form in a xhtml page

<p:editor value="#{managebeanX.valor}" />

but when I try to save this value through a sparql query it says:

virtuoso.jdbc4.VirtuosoException: SQ074: Line 2: SP030: SPARQL compiler, line 2: syntax error at 'Apple' before '-'

Here is the sparql query

INSERT INTO GRAPH <http://localhost:8890/Asst> {

<http://www.dominio.edu#Q1> rdf:type asst:Question; asst:prompt "adada <span class="Apple-tab-span" style="white-space:pre"></span>"^^xsd:string. }

The Blue text is the value of the p:editor. It' has html characters... So I think I need to scape those characters... but how?

View Replies View Related

Servlets :: Pagination Of Oracle Database Query Result

Jan 6, 2015

My query retrieves more than 5000 records from Oracle database. I want to display the records 100 per page. I know it is called pagination. Any detailed styp-by-guide or tutorial or example available?

View Replies View Related







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