Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle, JDBC, PreparedStatement

Status
Not open for further replies.

stefanwagner

Programmer
Oct 19, 2003
2,373
0
0
DE
I don't get the expected results for a PreparedStatement.
I get the expected Result, when using PostgreSQL:

Code:
String sql = "SELECT "
+ "   m.attribut, m.mapping   "
+ " FROM  "
+ "   mapping m "
+ "   , column c  "
+ " WHERE m.c_id = c.c_id  "
+ "   AND c.tablename = ? "
+ "   AND c.columnname = ? ";
try
{
	if (! isPrepared)
	{
		System.out.println ("prepare:");
		prepstmt = con.prepareStatement (sql);
		isPrepared = true;
	}
	
	prepstmt.setString (1, sTablename);
	prepstmt.setString (2, sColumnname);
	
	System.out.println ("exec query: " + sql);
	ResultSet rs = prepstmt.executeQuery ();
	
	while (rs.next ())
	{
		System.out.println ("rs.next()");
		int id = rs.getInt (1);
		// ...
The line 'rs.next ()' is never printed, but if I cut'n'paste the sql-String, and replace the '?' with values:
Code:
-- ...
WHERE m.c_id = c.c_id 
AND c.tablename = 'JOBS'
AND c.columnname = 'JOB_ID'
I get results via Web-iSql or on the sql-console.

And as menntioned above: the same application, running on a postgres-database returns values as expected.

There is no exception thrown, and I don't have an idea how to search for the error further.
 
Found out myself:

I used char(n) in both, oracle and postgres, and postgres truncates the values, while oracle fills them with blanks.

When I use nvarchar2(n) on oracle, it works like a charme.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top