JDBC :: How To Determine DATE Data Type Of Parameter If It Is Not Specified

Feb 2, 2015

Oracle JDBC driver determine the DATE data type of parameter correctly without any typecasting.

Example:
ps = conn.prepareStatement("SELECT ? FROM DUAL");
ps.setObject(1, Date.valueOf("2014-01-11")) ;
 
I have tried the same example with other database driver but it gives error.

PostgreSQL JDBC driver:
org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1
 
ps = conn.prepareStatement("SELECT ?");
ps.setObject(4, Date.valueOf("2005-01-01"));
 
so I want to know how Oracle JDBC driver determine the DATE data type of parameter.

View Replies


ADVERTISEMENT

JDBC :: Determine DATE Data Type Parameter If It Is Not Specified?

Feb 2, 2015

Oracle JDBC driver determine the DATE data type of parameter correctly without any typecasting.

Example:
ps = conn.prepareStatement("SELECT ? FROM DUAL");
ps.setObject(1, Date.valueOf("2014-01-11"));
 
How Oracle JDBC driver determine the DATE data type of parameter.

View Replies View Related

How To Insert Value Into SQL Server Table Column Of Data Type Datetime With JDBC

May 8, 2014

How can insert value into sql server column of data type 'datetime' with jdbc the methods in java.sql are 'setdate()' and 'setTime()'

How can I do this. I'm using java.time.LocalDateTime.

View Replies View Related

How To Get Date Data Type From MySQL To Java Format

May 22, 2012

In my project i am facing an problem, The My SQL Data base will accept the date format of yyyy/mm/dd only as "Date" data type but in my program i wants to use dd/mm/yyyy format. (i have this same format now) that's why I am unable to insert / retrieve it..

View Replies View Related

Addition Of Generic Type Parameter Causes Member Type Clash

Apr 22, 2014

Got a problem with generics, which I'm still pretty new at. Here's a program that compiles fine:

import java.util.ArrayList;
import javax.swing.JComponent;
public class Experiments {
public static void main(String[] args) {
ListHolder holder = new ListHolder();

[Code] ....

It's useless, but it compiles. If I change Line 14, however, to add a generic type parameter to the ListHolder class, Line 10 no longer compiles:

import java.util.ArrayList;
import javax.swing.JComponent;
public class Experiments {
public static void main(String[] args) {
ListHolder holder = new ListHolder();

[Code] ....

I get this error:

Uncompilable source code - incompatible types: java.lang.Object cannot be converted to javax.swing.JComponent
at experiments.Experiments.main(Experiments.java:10)

Apparently, the introduction of the type parameter leaves the compiler thinking that aList is of type Object. I can cast it, like this:

JComponent c = ((ArrayList<JComponent>)holder.aList).iterator().next();

That makes the compiler happy, but why is it necessary? How does adding the (unused) type parameter to the ListHolder class end up making the compiler think the aList member of an instance of ListHolder is of type Object?

View Replies View Related

JDBC :: Accessing Sys Refcursor As PLSQL Out Parameter

Oct 13, 2009

The 11g jdbc guide gives and example of how to access a pl/sql function RETURNING a cursor. We have a stored proc that returns about 5 out parameters one of which is a SYS_REFCURSOR. This is different from RETURNING a ref cursor. How to pass a resultset object to the stored proc. I presume the same java declaration is required:

ResultSet cursor;

pass this as a parameter to the stored proc. I have listed the 11g JDBC sample code below:

import oracle.jdbc.*;
...
CallableStatement cstmt;
ResultSet cursor;

[Code] ....

In the preceding example:
•     A CallableStatement object is created by using the prepareCall method of the connection class.
•     The callable statement implements a PL/SQL procedure that returns a REF CURSOR.
•     As always, the output parameter of the callable statement must be registered to define its type. Use the type code OracleTypes.CURSOR for a REF CURSOR.
•     The callable statement is run, returning the REF CURSOR.
•     The CallableStatement object is cast to OracleCallableStatement to use the getCursor method, which is an Oracle extension to the standard JDBC API, and returns the REF CURSOR into a ResultSet object.

View Replies View Related

Servlets :: Feature Detection - Determine Browser Type

Apr 22, 2014

I need to be able to detect IE 9, IE 10, IE 11 and the latest from Firefox and Chrome. The old method using the user-agent string is unreliable and not recommended. There is a different approach called, "Feature Detection". But I need to know what features to test to determine the browser. I can write it myself, or if there is a handy dandy API using feature detection already written that would be OK too.

View Replies View Related

Parametrized Array Type As Method Parameter?

Jul 31, 2014

I have the following method:

public static void doSomething(List<? extends GenericClass> input)
{
// op
}

^

This compiles and works, ensuring I can only pass in a List of a type extending GenericClass.But now I want it to accept an Array instead of List. This is where I'm stuck:

public static void doSomething(<? extends GenericClass>[] input)
{
// op
}

^

A wrong guess at the syntax which does not compile. One solution is to convert Array into ArrayList before calling the 1st method above, but I'd rather bypass this if possible.

View Replies View Related

Generic Method And Bound Type Parameter Errors

Jul 14, 2014

I am following this article [URL] .... till now I have made some code

This is my Interface

public interface Comparable<T> {
public int compareTo(T o);
}

And this is my class where I am using Bound Type Parameter on Generic Methods

public class GenericMethodBoundType {
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)

[Code] .....

What else I need to do both in main method and at what parameterized types I need to pass at the class?

View Replies View Related

How To Get Access To The Method With A Parameter Of Class Type Variable

Feb 19, 2014

how to get an access to the method with a parameter of class type variable, lets say: public void insert(Record newRecord, int pos)?

View Replies View Related

Process Data And Determine Winners - Two Dimensional Arrays

Feb 4, 2015

The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file: Pairs.txt

Which contains the data for each pair of skaters. The data consists of each skater's name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows:

Smith
Jones
Australia
5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8
4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5

The final score for each skater is the sum of the average of the two categories of score. Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners.

Here is my CLass:

public class Skaters {
private String name1;
private String name2;
private String country;
private double [] arrTech = new double [8];
private double [] arrArt = new double [8];
private double score;

[code]...

how do i print my 2 arrays using the file? i got the name1, name2 and counntry to print but im stuck on printing the scores that are stored in the arrays. Also, i have to print the average for each array. one is for techniques and the other one is artistic. as you can see i already wrote the code for it but im stuck in printing it.

View Replies View Related

Null Is What Type Of Data Type

Sep 3, 2007

method passing null to the called function, compiler would take that parmer as what type of paramer???

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 :: Loosing HTML Data Into Request Parameter?

Jan 23, 2014

In one jsp page, I submit a form with a message body with following html code (which is store in "MsgBody" in my request)

<!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">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

[code]....

But when I submit my form, I received in my servlet a parameter "MsgBody" without several tag like <html>/<body> ... do you know this behavior, by default tag are delete ?

public String execute(Map params, HttpServletRequest request, HttpServletResponse response) throws Exception {
String MsgBody = request.getParameter("MsgBody");.

I use Tomcat 7, maybe a tomcat behavior can influence for this tag loose in request param ?

View Replies View Related

Replacing Binary Data - Renew Expiry Date

Aug 3, 2014

Below is a method that i want to try to renew the expiry date.

Well I'm trying to read the file and rewrite the data into the txt file, is that possible?

Java Code:
public static void renew()throws IOException{
Scanner s=new Scanner(System.in);
Scanner s2=new Scanner(System.in);
Calendar calendar = new GregorianCalendar();
int year = (calendar.get(Calendar.YEAR));

[Code] ...

View Replies View Related

JDBC :: How To Call Parameterized Stored Procedure In Jdbc

May 17, 2014

calling a parameterized stored procedure in java jdbc from sql server.The stored procedure goes like this in sql

create proc patientreg
@id int
as
begin
select [patient_id],[Psurname], [pFirstname], [pMiddlename], [reg_date], [DOB], [Sex], [Phone_num], [Addr],[Email],[dbo].[fncomputeage](DOB) from [dbo].[Patient_registration] where [patient_id] = @id
end
please note dbo.fncompute(DOB) is a function

To call it in jdbc it goes like this

try{
String str = "{call patientreg(?)}";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbcdbc:GeneralHospit al");
cstmt = con.prepareCall(str);
cstmt.setInt(1, Integer.parseInt(t.getText()));

[code]....

after doing it this way it throwing an exception: Error:java.sql.SQLException: Parameter 1 is not an OUTPUT parameter.

View Replies View Related

Read Date From File / Calculate And Then Displays That Data In Table Format On Screen

Apr 22, 2015

The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:

Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:

111
251.41
222
402.00

With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.

import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {

[Code] .....

View Replies View Related

Data Type That Can Store Methods

Mar 21, 2015

I was wondering is there any data type that can store method?

View Replies View Related

Using Boolean Data Type In Program

Sep 25, 2014

While practicing java i have came across boolean data type. i have executed below program but i am not sure how i got output of the program like below:

10 > 9 is true

Here is my program:

class BoolTest3
{
public static void main(String args[])
{
System.out.println("10 > 9 is "+(10>9));
}
}

My question is: how this program will come to know that 10>9 true or false.. how bolean data type used in this program.

View Replies View Related

Creating Array With Multiple Data Type?

Oct 10, 2014

i need to create an array with attributes name, gender, phone, age.and then sort acording to age in ascending order.

i created like this,

public class Array{
private String[] name={"ram", "katy", "priti", "john"};
private String[] gender={"male","female","female","male"};
private int[] phone={989898089,89898989,8982989089,898908989};
private int[] age={45,24,30,28};
  public void printarray(){

[code]....

This code sorts the age attribute alone and when printing ouput it swaps one person's age to other person, how to make it correct

View Replies View Related

Passing Primitive Data Type Arguments

Jun 5, 2014

I am totally new to Java. What is the purpose of this method?

Flow of the int x=3; like where does the 3 go step by step?

Passing Primitive Data Type Arguments (from oracle java tutorials)

Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost. Here is an example:

public class PassPrimitiveByValue {
public static void main(String[] args) {
int x = 3;
// invoke passMethod() with
// x as argument
passMethod(x);

[Code] ....

View Replies View Related

Double Data Type Outputting To Exponent?

Nov 9, 2014

I was struggling to use BufferedReader to extract some data and then perform some calculations and then have the results as outputs.

I haven't quite solved that issue but in order to progress, I hard coded some values into my application and proceeded with the actual calculation loops etc.

Currently, the value out put from one of my calculations is given as:

1.1704926E7

How can I make the console show it in a natural way. I've performed the calculation manually and it should be 11704926.5 I don't want to lose that .5!

View Replies View Related

Passing Reference Data Type Arguments

Oct 21, 2012

Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost.

Reference data type parameters, such as objects, are also passed into methods by value. This means that when the method returns, the passed-in reference still references the same object as before. However, the values of the object's fields can be changed in the method, if they have the proper access level.For example, consider a method in an arbitrary class that moves Circle objects:

public void moveCircle(Circle circle, int deltaX, int deltaY) {
// code to move origin of
// circle to x+deltaX, y+deltaY
circle.setX(circle.getX() + deltaX);
circle.setY(circle.getY() + deltaY);

// code to assign a new
// reference to circle
circle = new Circle(0, 0);
}

Let the method be invoked with these arguments: moveCircle(myCircle, 23, 56)

Inside the method, circle initially refers to myCircle. The method changes the x and y coordinates of the object that circle references (i.e., myCircle) by 23 and 56, respectively. These changes will persist when the method returns. Then circle is assigned a reference to a new Circle object with x = y = 0. This reassignment has no permanence, however, because the reference was passed in by value and cannot change. Within the method, the object pointed to by circle has changed, but, when the method returns, myCircle still references the same Circle object as before the method was called.

View Replies View Related

Unable To Use Double Data Type In For Loop

Aug 12, 2014

I am trying to use double data type in a for loop for precise operations and just to see if there could be any problem doing that I tested a small code :

public class doubleLimit {
public static void main(String[] args){
for(double i=-0.1;i<=0;i+=0.01)
System.out.println(i); }}

The output I was expecting is :
-0.1
-0.09
-0.08
-0.07
-0.06
-0.05
-0.04
-0.03
-0.02
-0.01
0.00

But the output of the code is :
-0.1
-0.09000000000000001
-0.08000000000000002
-0.07000000000000002
-0.06000000000000002
-0.05000000000000002
-0.040000000000000015
-0.030000000000000013
-0.02000000000000001
-0.01000000000000001
-1.0408340855860843E-17

Why is the code not working the way I expected, I think it has something to do with any property of double but I am not sure.

View Replies View Related

Adding Any Type Of Data To A Generic List?

Aug 28, 2014

Is this the proper way to add to a generic list? My code works just fine, but I got this feeling that there might be some kind of flaw in it or something. Is this pretty much the basic way to add any type of data to a generic list?

import java.util.LinkedList;
public class ListOfGeneric<E> {
private LinkedList<E> myList;

ListOfGeneric(){
myList = new LinkedList<E>();

[Code] ....

View Replies View Related

Splitting Date String By Date And Time And Assigning It To 2 Variables?

Jul 17, 2014

I have an requirement of splitting a Date-Time String i.e. 2013/07/26 07:05:36 As you observe the above string has Date and Time with space in between them.

Now I want just want split the string not by delimiter but by length i.e. after 10th place and then assign it to 2 variable i.e. Date <----2013/07/26 and Time <---07:05:36 separately.

View Replies View Related







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