473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

run a sql query through JDBC .....

dmjpro
2,476 2GB
if i run a query like (select sysdate from dual) then it runs easily on oracle client .. like SQL plus or Navigator ......

but if i run this through JDBC then it falshes an error .... missing mandatory paramter

plz help me .... thanxxxx
Mar 22 '07 #1
4 3213
sicarie
4,677 Expert Mod 4TB
if i run a query like (select sysdate from dual) then it runs easily on oracle client .. like SQL plus or Navigator ......

but if i run this through JDBC then it falshes an error .... missing mandatory paramter

plz help me .... thanxxxx
Can you post the line that has your query in it, and copy and paste the exact error message?
Mar 22 '07 #2
dmjpro
2,476 2GB
ok kkkk ... here is my code

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. class QueryTest
  4. {
  5.   public static void main(String args[]) throws Exception
  6.   {
  7.       Class.forName("oracle.jdbc.driver.OracleDriver");
  8.       Connection l_con = DriverManager.getConnection("jdbc:oracle:thin:@172.20.0.207:1522:BCCLPROD","coalnetapps","coalnetapps");
  9.       Statement l_stmt = l_con.createStatement();
  10.       ResultSet l_rs = l_stmt.executeQuery("(select sysdate from dual)");
  11.       while(l_rs.next()) System.out.println("Debasis: " + l_rs.getString(1));
  12.       System.out.println("Debasis Yahoooooo .....");
  13.   }
  14. }
and the error message is ....

java.sql.SQLException: ORA-01009: missing mandatory parameter

now explain plz .......
thanxxxx
Mar 22 '07 #3
sicarie
4,677 Expert Mod 4TB
ok kkkk ... here is my code

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. class QueryTest
  4. {
  5.   public static void main(String args[]) throws Exception
  6.   {
  7.       Class.forName("oracle.jdbc.driver.OracleDriver");
  8.       Connection l_con = DriverManager.getConnection("jdbc:oracle:thin:@172.20.0.207:1522:BCCLPROD","coalnetapps","coalnetapps");
  9.       Statement l_stmt = l_con.createStatement();
  10.       ResultSet l_rs = l_stmt.executeQuery("(select sysdate from dual)");
  11.       while(l_rs.next()) System.out.println("Debasis: " + l_rs.getString(1));
  12.       System.out.println("Debasis Yahoooooo .....");
  13.   }
  14. }
and the error message is ....

java.sql.SQLException: ORA-01009: missing mandatory parameter

now explain plz .......
thanxxxx
You're missing a try-catch, i know a lot of compilers will complain about that...
Mar 22 '07 #4
nathj
938 Expert 512MB
Ok, I'm pretty new to this whole thing but I tend to use a class specifically for database connections in conjunction with a simple properties file. Both are shown below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class DBConnector 
  3. {
  4.  
  5.     private String className;
  6.     private Properties jdbcConnectProps = new Properties();
  7.     private String connectionString;
  8.  
  9.     public Connection getJDBCConnection(String dbUserId, String dbPassword)
  10.     {
  11.         Connection conn = null;
  12.         try
  13.         {
  14.             Class.forName(this.className);
  15.             conn = DriverManager.getConnection(this.connectionString, dbUserId, dbPassword);
  16.         }
  17.         catch(Exception e)
  18.         {
  19.             // TODO: ND - use of ESF Exceptions relating to databases - may need to generate a new Exception class
  20.         }
  21.  
  22.         return conn;
  23.     }
  24.  
  25.     public void loadProperties(String propsLocation)
  26.     {
  27.         try
  28.         {
  29.             this.jdbcConnectProps.load(new FileInputStream(propsLocation));
  30.         }
  31.         catch(Exception e)
  32.         {
  33.             // TODO: ND - use ESFIOException as this means no props file found
  34.         }
  35.     }
  36.  
  37.     public void setClassName(String key)
  38.     {
  39.         try
  40.         {
  41.             this.className = jdbcConnectProps.getProperty(key);
  42.         }
  43.         catch(Exception e)
  44.         {
  45.             // TODO: ND - use ESFRetrievalException as this means we could not get the properties
  46.         }
  47.  
  48.     }
  49.  
  50.     public void setConnectionString(String connectString)
  51.     {
  52.         this.connectionString = connectString;
  53.     }
  54.  
  55.     public String getConnectionString()
  56.     {
  57.         return this.connectionString;
  58.     }
  59.  
  60.     public String getClassName()
  61.     {
  62.         return className;
  63.     }
  64.  
  65.     // @Override
  66.     // public Connection getBlackboardJDBCConnection() {
  67.     // // TODO Auto-generated method stub
  68.     // return null;
  69.     // }
  70.     //
  71.     //
  72.     // @Override
  73.     // public Connection getCMISJDBCConnection() {
  74.     // // TODO Auto-generated method stub
  75.     // return null;
  76.     // }
  77. }
  78.  
The properties file is as follows:
Expand|Select|Wrap|Line Numbers
  1. #Class names for different databases
  2. jdbc.sqlserver.classname=com.microsoft.sqlserver.jdbc.SQLServerDriver
  3. #jbdc.oracle.classname=
  4. #jdbc.mysql.classname=
  5.  
What this enables me to do is the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. package org.esf.test;
  3.  
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import org.esf.utils.DBConnector;
  9.  
  10. public class GetUserQueries
  11. {
  12.     private final DBConnector dbc = new DBConnector();
  13.     private ResultSet usersByDSK = null;
  14.  
  15.  
  16.     public static void main(String[] args)
  17.     {
  18.         GetUserQueries guq = new GetUserQueries();
  19.         guq.run();
  20.     }
  21.  
  22.     public GetUserQueries()
  23.     {
  24.         dbc.loadProperties("E:/full/path/to/properties/jdbcConnection.properties");
  25.         dbc.setClassName("jdbc.sqlserver.classname");
  26.         dbc.setConnectionString("jdbc:sqlserver://machine:port;databaseName=mydatabase");
  27.     }
  28.  
  29.     public void run()
  30.     {
  31.         // get a rs
  32.         usersByDSK = getUserNamesByDSK(1);
  33.         // print rs
  34.         System.out.println(toString());
  35.     }
  36.  
  37.     public ResultSet getUserNamesByDSK(int dsk)
  38.     {
  39.         Statement queryStmt;
  40.         ResultSet queryResult = null;
  41.         try
  42.         {
  43.             queryStmt = dbc.getJDBCConnection("username", "password").createStatement();
  44.             queryResult = queryStmt.executeQuery("Select user_id from users where data_src_pk1 = " + dsk);
  45.         }
  46.         catch(SQLException sqlEx)
  47.         {
  48.             System.out.println("Oh Poo - can't query");
  49.         }
  50.         return queryResult;
  51.     }
  52.  
  53.     public String toString()
  54.     {
  55.         StringBuilder sb = new StringBuilder();
  56.  
  57.         try
  58.         {
  59.             while(usersByDSK.next())
  60.             {
  61.                 // retrieve and print the values for the current row
  62.  
  63.                 sb.append("User : " + usersByDSK.getString("user_id") + "\n");
  64.             }
  65.         }
  66.         catch(SQLException e)
  67.         {
  68.             System.out.println("Oh Poo - results issues");
  69.             //TODO: ND Handle this exception properly
  70.         }
  71.  
  72.         return sb.toString();
  73.     }
  74. }
  75.  
This is a very specific checking system to ensure I got the results I expected.

Hopefully that's clear enough. I know this is for SQL Server but the same principles hold true for Oracle - I believe.

Anyway, hope that helps and if not ask again and I'll try to help some more.

nathj
Jun 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike Read | last post by:
Hi I using Java and JDBC to connect to MS SQL server 2000 (using the MS drivers msbase,msutil and mssqlserver.jars). Sometimes it takes a long time for statement.executeQuery to return and...
0
by: Nils Valentin | last post by:
Hi MySQL Fans ;-), Is it possible that the 3.08 series allows to connect to 4.0.14 versions but not to the 4.1 alpha-versions ? I get belows error when tryig to connect from DbVisualizer which...
29
by: Mainlander | last post by:
An ISP I belong to uses Majordomo for their mailing list system. I'd like to encourage them to move to a system that uses a database, preferably psql which they already run on their server....
3
by: Bob McDermott | last post by:
Hi Folks, We use JDBC to connect to a DB2 database on an AS/400. We wrote a crude query tool that allows us to send SQL to the DB and get results, but it doesn't have any convenience features...
3
by: Stijn Vanroye | last post by:
Hi List, I'm running a query on a not-so-small db. Mostly this query runs fast enough, but every once in a while the query takes a long time to complete in wich case the users start banging away...
1
by: aleicaro | last post by:
Hi, I have a problem with db2 query... I access to my database via jdbc using com.ibm.db2.jcc.DB2Driver. I build my string query in a java class. I have some parameters in my query, but there are...
1
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
2
by: grabit | last post by:
Hi Mary this is the problem child (query) <!---Query db for page info---> <cfquery name="showtopics" datasource="parrots"> SELECT categories.catID, threads.threadID, threads.posttype,...
2
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
2
by: cypriot | last post by:
Hi. I am developing an application program in java. I use MsAccess for keeping data. I had a problem with sql insert method. public void AddPatient() { String...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.