Get BaseResourceException with JDBC ds.getConnection()

Hi,
I have created a stateless sessionbean with the intension to connect to the default SAP database by JDBC. Therefore I have created 3 project: a dictionairy project, a enterprise java bean project and a j2ee application project. Within the j2ee application project I have created a datasource alias:
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-source-aliases SYSTEM "data-source-aliases.dtd">
<data-source-aliases>
     <aliases>
          <data-source-name>${com.sap.datasource.default}</data-source-name>
          <alias>UNIQEMA_CONTACT_US</alias>
     </aliases>
</data-source-aliases>
And in the ejb module project I have created also a reference to the datasource:
               <resource-ref>
                    <res-ref-name>UNIQEMA_CONTACT_US</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Application</res-auth>
                    <res-sharing-scope>Shareable</res-sharing-scope>
               </resource-ref>
I have also created the following create method in the ejb :
     public void ejbCreate() throws CreateException {
          try {
//               Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
               Context ctx = new InitialContext();
               DataSource ds = (DataSource) ctx.lookup("java:comp/env/UNIQEMA_CONTACT_US");
               conn = ds.getConnection();
          } catch (Exception e) {
               throw new CreateException("e.getMessage");
But when the ejb excutes the ds.getConnection() I got the following error:
com.sap.engine.services.connector.exceptions.BaseResourceException: Cannot get connection. Reason: the thread of component "ejbContexts/sap.com/com.atosorigin.uniqema.contactus.appl/uniqema_contact_us_country" in application "sap.com/com.atosorigin.uniqema.contactus.appl" is currently associated with a restricted resource set and it is not allowed to get connection within it.
Please can someone say what I have done wrong a which feature I have forgotten to set.
regards,
Sander Valkenburg

Hi Sander,
another note on using DS connections:
1. connection as you may know are scarce resources, meant to be shared among apps. Storing a connection in a instance variable of a bean is not a good idea for another reason to: the database times out connections too!
2. proper usage would be something like this
Connection conn = null;
try {
  // acquire conn.
  conn = ds.getConnection();
  // do something with it
} catch( ..) {
} finally {
  // give conn back to pool
  try { if () conn.close(); } catch(Exception e) {}
Regards
Gregor

Similar Messages

  • Getting Started With JDBC

    I have successfully loaded PERSONAL ORACLE and JAVA JDK 1.2.2 on a WIN 98 client.
    QUES:
    o Can I connect from a JAVA program to ORACLE in this environment.
    o Can anyone assist me in determining whether I need any drivers beyond which are loaded in the typical JAVA and PERSONAL ORACLE installation?
    o How do I connect from JAVA to ORACLE? Is there any ORACLE doc that explains this step-by-step?

    My question is there a Class 4 JDBC driver and DB available for free download? Yes and yes respectively.
    MySQL is a good system for a beginner; give it a go.
    http://www.mysql.com/doc/en/Java.html

  • How to get the field's type in the database with jdbc?

    How to get the one filed's type(varchar,int,long...etc) with jdbc??
    Can u help me??
    It's best that giving a sample code..

    Thx for your reply,BheegaChicken! But i use it with
    oracle9i jdbc..It doesn't return to my the fields
    type correctly..
    This is problem is caused by oracle jdbc??
    Can u tell me??It depends on the driver classes you are using... some of them don't have an implementation for those methods and you won''t get anything useful. Check the driver documentation.
    ***Annie***

  • Getting inline schema documentation with JDBC

    Some databases (Oracle, IBM DB2) provides possibility to add additional documentation to database schema (using SQL commands COMMENT ON, LABEL ON). This is information is preserved together with other meta-information about tables in the database.
    Is it possible to access this documentation with JDBC?
    Best,
    Maciej
    Edited by: dzieciou on Feb 13, 2009 3:16 AM

    Frank
    - is the JDBC jar file required on the "Server" side (RHEL 5.3) or "Client" side (Windows XP) (sorry if I'm using the wrong terminology, I'm still getting started with OWB)?
    Yes. At the client JDBC driver is required to import the metadata (tables\views\etc) and at the server to execute the code generated by code templates.
    - the JDBC driver requires a .dll (Win) / .so (Linux); is this possible with OWB? Or does OWB accept only "pure" JDBC drivers?
    Not sure about this one - the .dll and .so are OS files , i think the JDBC driver should figure it out if they are configured correctly on the OS
    - is there any possibility to debug the JDBC access (some kind of log file, perhaps)?
    There are two ways you can debug
    1) Logging at the OWB level (client side) -
    The following blog to demonstrates how to do it
    http://blogs.oracle.com/warehousebuilder/2009/11/how_to_turn_on_logging_for_owb_112_design_client.html
    2) JDBC Driver logging -
    Few JDBC drivers provides logging , you can specify the log file as part of your JDBC URL. Check the documentation of your JDBC driver (PI JDBC driver) whether it provides you that feature.
    Regards,
    Suraj.

  • Problem with JDBC and Tomcat

    I don't know where the problem originate, the only thing in my memory is that the program worked very well on my PC yesterday, but today, without even slightest change, it doesn't work anymore. As to debug it, I simplified the codes to the least, but it still refuse to work. I was beaten down by this problem totally, and cannot make out any solution for it, so, I come here, hoping to find a warrior to kill this damned bug for me.
    My program is a Servlet, but for the purpose of debugging, I have recode it to an Application/Servlet. When run as a application, I can get the result expected, but as a Servlet, :-(, maybe you should see it by yourself. My server software is Tomcat 4.1.15, and the JDK version is 1.4.0. To excute this program, you should add Data Source "Test" to ODBC.
    ///////////////////////code begins/////////////////////////
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class Ex extends HttpServlet
         int ErrorType = 0;
         String err = new String("");
         public static void main(String args[]) throws Exception{
              Ex cEx = new Ex();
              cEx.init();     
              System.out.println(cEx.ErrorType);     
         public void init() {
              String url = "jdbc:odbc:Test";
              ErrorType = 3;     //passed
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              } catch (ClassNotFoundException e) {
                   e.printStackTrace();
                   ErrorType = 1; //trapped in Class.forName
              try{
                   Connection c = DriverManager.getConnection(url);
              } catch (SQLException e) {
                   e.printStackTrace();
                   ErrorType = 2; //trapped in DriverManager.getConnection
                   err = e.getMessage();
         public void service(HttpServletRequest req, HttpServletResponse res)
                   throws IOException {
              res.setContentType("text/html; charset=GB2312");
              PrintWriter out = res.getWriter();
              out.println("Success " + "<p>" + ErrorType + "<p>" +err);
              out.close();
    //////////////////////////code ends///////////////////////////////
    The result from the Servlet tell me that the problem occurred within the connection process, I don't know who should be responsible to this - Tomcat or JDBC?

    If you could print the exception that you got then that would help :) In the mean time, I could make a guess. It is unlikely that your application server (in this case, Tomcat) is blocking connections from your servlet. So the problem is either with JDBC directly or with the underlying datasource. It seems unlikely that it is JDBC given that you have stated that the code has not changed and it works in application form.
    My guess would be that you are coming up against some sort of security constraint (eg: your DBMS is letting you log in from one IP but not another?, your Java plug-in security policy is disallowing the connection?). It's hard to say.
    But if it works as an application but not via a servlet then you could try putting this in your java.policy file, which is located in the directory where your plug-ins are installed (eg: "C:\Program Files\Java\<version>\lib\security\") on Windows systems;
    permission java.net.SocketPermission "bend xp:1099", "listen,connect,accept";
    Try that, see if it works :)
    Ben

  • Problem with jdbc:odbc returning incorrect number of rows.

    Hello,
    Am sure i have done something stupid, but i have an issue with jdbc:odbc ....
    It is a simple sceanrio that i have coded umpteen times before ...
    I have the following ....
    1. Connection to DB2 on an IBM i5 (I apologise for not using native drivers from jt400.jar, but i had an ODBC code example and was in a rush - no excuse i know)
    2. Statement object created from connection above
    3. A string with my SQL in it
    4. A result set for the results.
    These are created as follows:
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection(ODBCSource, userID, password);
    if (con == null) {
    // error handling not relevant here
    } else {
    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String SQL = "select * from table";
    ResultSet rs = s.executeQuery(SQL);
    i then try to loop ....
    while (rs.next() )
    // stuff
    however, i only ever get one result .... if i stick in the check for isLast, the first loop hits this check, i get my little status message, and the loop ends.
    while (rs.next() )
    if (rs.isLast() )
    System.out.println("I am on last record");
    BUT if i run the SQL
    "select count(*) from table" ... i get a count of 148 !!
    I tried setting the FetchSize through setFetchSize(), but made no difference.
    This is running on a JBoss server 4.2.1GA, JDK is "jdk1.6.0_02" .... i have a suspicion that this may be a JBoss specfic issue, as this exact code runs just fine on the Domino platform that it was originally on, if this is the case, i apologise for wasting everyones time .... but would still appreciate any pointers you can give me.
    Cheers

    Hello,
    Thanks for the reply, I am not sure i follow what you are saying.
    I only mentioned JBoss as it is the application server that we have deployed to and because the orignal code ran fine on a Domino server, I will take your advice and try to run it through in debug rather than running actually on the application server.
    Am i incorrect in my assumption that if "select count(*) from table" gives a count of 148, i should expect 148 records in a result set created from "select * from table" ? This is all rather new to me so i apologise if this is incorrect, I'd love to know why this is incorrect so i dont make similar mistakes in future.
    Also, If i run this same code on the previous platform, i get 148 iterations of the code contained within
    while (rs.next() ) { ... }
    When the war file is deployed to JBoss, the same SQL statement gives a result set that only iterates once for
    while (rs.next() ) { ... }
    The previous platform as I say was domino, but it was running as a lotus notes java agent (despite not using any notes documents etc) as it happened to be where the web pages that call this process were located. It is possible that some of the main code has changed as I had cut and paste the code into a servlet using MyEclipse, but i have double checked the bit that does this SQL request and it is identical
    To complete the picture, the new servelt is then called from the action tag on the submit form on a JSP, when it ends the servlet redirects via the requestdispacher to success or failure jsp pages depending on the outcome of the processing.
    Thank you again for your help.

  • How to get Connection with Oracle8i In OAS through EJB?

    I've created a EJB in OAS,and invoked its method successfully.However,when I added a method using JDBC to get connection to Oracle8i,it failed.The source code is as below:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection l_connection = DriverManager.getConnection(......);
    then there is an Exception about omg.CORBA;
    but using the code in an application to connect to Oracle8i directly is ok.
    Would you please give me some advices?
    null

    Were you able to fix your problem?
    I am getting a similar error. I am using the Reference Implementation from J2EE SDK.
    I can connect to Oracle8i with JDBC in a Java Application but when I put my code in my Entity Bean, I get a NoClassFoundError on the oracle.jdbc.OracleDriver.
    Any suggestions?
    Al
    [email protected]

  • Problems with JDBC-ODBC Driver

    Hello,
    I am trying to access a DSN on my windows with a dedicated DB driver of some company. so i used the JDBC-ODBC connector.
    when launching the java code, and debugging the problem i get the following error:
    DriverManager.getConnection("jdbc:odbc:priority32;UID=Manager;PWD=keren")
        trying driver--className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@16caf43--
        trying driver--className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@66848c--
    *Driver.connect (jdbc:odbc:priority32;UID=Manager;PWD=keren)
    JDBC to ODBC Bridge: Checking security
    No SecurityManager present, assuming trusted application/applet
    JDBC to ODBC Bridge 2.0001
    Current Date/Time: Tue Aug 12 07:50:37 VET 2008
    Loading JdbcOdbc library
    Allocating Environment handle (SQLAllocEnv)
    hEnv=50338088
    Allocating Connection handle (SQLAllocConnect)
    hDbc=50338256
    Connecting (SQLDriverConnect), hDbc=50338256, szConnStrIn=DSN=priority32;UID=Manager;PWD=keren
    *Connection.getMetaData
    *DatabaseMetaData.getDriverName
    Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=6, len=300
    tabula.dll
    *DatabaseMetaData.getDriverVersion
    Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=7, len=300
    07.00.0000
    *DatabaseMetaData.getDriverName
    Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=6, len=300
    tabula.dll
    Driver name:    JDBC-ODBC Bridge (tabula.dll)
    *DatabaseMetaData.getDriverVersion
    Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=7, len=300
    07.00.0000
    Driver version: 2.0001 (07.00.0000)
    Caching SQL type information
    *Connection.getMetaData
    *DatabaseMetaData.getTypeInfo
    Allocating Statement Handle (SQLAllocStmt), hDbc=50338256
    hStmt=50339424
    Get type info (SQLGetTypeInfo), hStmt=50339424, fSqlType=0
    Number of result columns (SQLNumResultCols), hStmt=50339424
    value=15
    Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=10, len=300
    03.52.0000
    Fetching (SQLFetch), hStmt=50339424
    Column attributes (SQLColAttributes), hStmt=50339424, icol=1, type=2
    value (int)=12
    Column attributes (SQLColAttributes), hStmt=50339424, icol=1, type=3
    value (int)=129
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    CHAR
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=12
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    CHAR(1)
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=1
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    RCHAR
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=12
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    REAL
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=6
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    INT
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=4
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    UNSIGNED
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=4
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    TIME
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=10
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    DATE
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=11
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    DATE
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=9
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    DAY
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=4
    Fetching (SQLFetch), hStmt=50339424
    Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
    DECIMAL
    Get integer data (SQLGetData), hStmt=50339424, column=2
    value=3
    Get integer data (SQLGetData), hStmt=50339424, column=3
    value=0
    Fetching (SQLFetch), hStmt=50339424
    End of result set (SQL_NO_DATA)
    *ResultSet.close
    Free statement (SQLFreeStmt), hStmt=50339424, fOption=1
    *ResultSet has been closed
    Get connection info (SQLGetInfo), hDbc=50338256, fInfoType=44
    int value=0
    Get connection info (SQLGetInfo), hDbc=50338256, fInfoType=121
    RETCODE = -1
    ERROR - Generating SQLException...
    SQLState(S1096) vendor code(0)
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Information type out of range
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbc.SQLGetInfo(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbcConnection.checkBatchUpdateSupport(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at WigsUpdate.main(WigsUpdate.java:25)
    getConnection returning driver--className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@66848c--what can be done?
    thank you very much

    HimberJack wrote:
    oh now i understand.
    i got a very unknown company which supplied the ODBC driver, but they dont have java driver...
    so I have nothing to do about it?The choices are find a different driver or use the one you have.
    The one you have doesn't do batches.
    Finding a different driver could involve the following.
    - Buying one from somewhere else
    - Pay someone to write one.
    - Write a driver yourself.
    All of those are somewhat dependent that the "unknown company" has an API that supports that. You (or someone) could also figure out the file format of the "unknown company" as well and then write one.

  • Error when create XMLType object with JDBC connection

    Hello, I try to get an XMLType object with JDBC, but it doesn't work. Can somebody help me?
    My code is :
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@"+"a02w03:1521:PROJET", "scott", "tiger");
    OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select xmldoc from cv_col");
    ResultSet rset = stmt.executeQuery();
    OracleResultSet orset = (OracleResultSet) rset;
    while(orset.next())
    OPAQUE o = orset.getOPAQUE(1);
    System.out.println(o.getSQLTypeName());
    XMLType poxml = XMLType.createXML(o);
    My database table:
    CREATE TABLE cv_col (
    XMLDoc xmltype
    Execution: The SQL type name "SYS.XMLTYPE" is write and then I obtain the error:
    Exception in thread main
    java.lang.NoSuchMethodError: java.lang.String oracle.jdbc.internal.OracleConnection.getProtocolType()
         at oracle.xdb.XMLType.initConn(XMLType.java:2072)
         at oracle.xdb.XMLType.<init>(XMLType.java:903)
         at oracle.xdb.XMLType.createXML(XMLType.java:493)
         at Prog.main(Prog.java:26)
    Process exited with exit code 1.
    Thank you, very much!

    What platform are you using for the database, what are you running your code on.
    Which database version are you working with.. What is your class path. What version of JDBC and OCI are in the client environment, eg what are CLASSPATH and PATH / LD_LIBRARY_PATH settings. Have you tested your code using a simple IDE like Oracle's JDeveloper or run it from directly from the command line.

  • Help needed with JDBC - please help! (newbie)

    hi all
    i m new to jdbc
    i have installed MySQL server on my winxp machine
    i used the command:
    mysql -p -u root
    Enter password: ****now when writing a prog i m getting a prob at this piece of code:
    Connection con=DriverManager.getConnection("jdbc:odbc:books","root","root");wot is wrong wid this code?
    please help......
    thanks in advance

    There are about 20 different things that could be wrong a this point; I'm not going to list them all. If you want specific help, you need to post specific information. This is usually done by posting either a stack trace from an exception, or a more complete section of code and a description of the problem and ALL the symptoms. You have all the information on what you've done, we have none of it.
    Instead of trying to diagnose whats wrong with your ODBC setup, I'm going to give you some strong advice; don't use ODBC with JDBC if you can avoid it, and with MySQL you can avoid it. It makes things simpler, less can go wrong, and you don't have to configure a DSN on every machine that you install the program on.
    To use "pure" JDBC without ODBC for MySQl:
    1) download the JDBC driver (you might already have this)
    http://dev.mysql.com/downloads/connector/j/3.1.html
    2) follow the installation instructions
    http://dev.mysql.com/doc/refman/5.0/en/java-connector.html
    In particular, make sure your classpath is set correctly
    3) Here's an example of loading the driver and establishing a connection
    http://dev.mysql.com/doc/refman/5.0/en/cj-connect-with-drivermanager.html
    Note the form of the connection URL,
    "jdbc:mysql://localhost/test?user=monty&password=greatsqldb"
    This is what an URL without ODBC looks like; there is no DSN, which means no DSN has to be configured.
    4) The MySQL database has some built-in security, to prevent malicious connections from outside computers. Solutions to that and other common problems are here:
    http://dev.mysql.com/doc/refman/5.0/en/cj-faq.html

  • P-R-O-B-L-E-M with JDBC thin driver

    Thank you gmagana!
    I did not manage to make this code connect to Oracle at all:
    import java.sql.*;
    public class jdbcThin {
    public static void connect() {
              String     url = "jdbc:oracle:thin:uName/passW@myDatabase:1521:orcl";
              try {
                        Class.forName ("oracle.jdbc.driver.OracleDriver");
                   Connection conn = DriverManager.getConnection( url );
                   System.out.println ("The Oracle thin driver loaded!");
              catch (ClassNotFoundException e) {
                   System.out.println ("Did not load driver.");
                   e.printStackTrace ();
              catch (SQLException e) {
                   System.out.println ("Did not load driver.");
                   e.printStackTrace ();
    public static void main( String args[] ) {
              connect();
    // Do "statement" stuff after I successfully connect to Oracle.
    My setup:
    1. jdbcThin.class in located in: ~/runMe/jdbcThin.class
    2. Unextracted classes12.zip in: ~/runMe/classes12.zip
    3. Java Runtime: ~/runMe/bin or
    ~/runMe/jre/bin
    Command line:
    %~/runMe> java jdbcThin
    Message:
    Did not load driver.
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at jdbcThin.connect(Compiled Code)
    at jdbcThin.main(Compiled Code)
    %~/runMe>
    Tried running it with classpath re-direction:
    %~/runMe> java -classpath /runMe classes12.zip.jdbcThin
    Message:
    zip.jdbcThin
    Can't find class classes12.zip.jdbcThin
    %~/runMe>
    I am not permitted to change anything in .cshrc or .profile where
    I could use/> setenv classpath path1:path2: ~etc.
    Oh, JAVA gods(!) I am stuck. <quite pissed> :(
    ...and what am I doing wrongly with JDBC thin?!
    H E L P !!!!!!!!!!!!!!!!!!!

    Thanks Shirish! (Symmetrical WRT sound!)
    Here is my adaptation of that snippet which compiles, except for one error:
    Class OracleDriver not found. How did you handled your classes12.zip and
    your class path? Exactly what should happen at the command line?!
    That is really my BIGGEST issue with these vendor drivers outside JDK.
    I am aware that many styles work, but given the EXACTLY correct environment
    setting. This is my main issue and why I specified my exact directories.
    1. If Oracle is in: ~ root/Oracle
    2. Thin driver in: ~ root/drivers/classes12.zip
    3. My connection code in: ~root/sources/connDB.class
    What EXACTLY should happen to compile and run:
    import java.sql.*;
    public class connDB {
    public static void connect() {
              Connection     conn;
              Statement     stmt;
              ResultSet          rtset;
              String          SQL;
              try {
    DriverManager.registerDriver(new OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:" + instance, username, password);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    rtset = stmt.executeQuery(SQL);
    catch( SQLException sqle ) {
                   System.out.println ("Did not load driver.");
                   sqle.printStackTrace ();
    public static void main( String args[] ) {
              connect();
    I am sitting @~root/sources>
    So far I have no problem running any non-driver associated classes from there.
    But how do I make my code find this OracleDriver?! And should classes12.zip
    be extracted? I was told it should remain intact. Point is where should it be
    or what command line "command" gets this connDB.class + OracleDriver to run?

  • Updating primary key with jdbc

    Trying to update a primary key with:
    public static void updateTAXID(String coid,String accountnumber,String oldTAXID,String fundname,String newTAXID){ Properties props = TradeHelper.loadProperties(); Connection conn = null; PreparedStatement st = null; String sql ="update FinancialAccount set taxid=? " + "where dealernumber=? and " + "taxid=? and " + "fundname=? and " + "accountnumber=?"; try{ Class.forName(props.getProperty("driver")); conn = DriverManager.getConnection(props.getProperty("brokerageurl"), props.getProperty("user"),props.getProperty("password")); st = conn.prepareStatement(sql); st.setString(1, newTAXID); st.setString(2, coid); st.setString(3, oldTAXID); st.setString(4, fundname); st.setString(5, accountnumber); st.executeUpdate(); System.out.println("Update: new tx:"+newTAXID+":"+"Ol tx: "+oldTAXID+" act:"+accountnumber); conn.close(); st.close(); }catch(Exception e){ e.printStackTrace(); } }
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)         at com.mysql.jdbc.PreparedStatement.exe
    Am I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?

    iketurner wrote:
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.exeAm I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?If you take the error message at its word then the problem is not that you are not permitted to update a primary key but that the values you are trying to use is already in use.
    I'll leave it you DBA and/or Data Modeler/Architech to decide if it is a good idea to update the value or not.

  • Multiple Queries with JDBC

    Hello. I'm somewhat new to all of this, so forgive me if this is something really basic.
    I'm developing an application which must interact with my MySQL database pretty frequently, however it seems to me that I am unable to, essentially, have multiple ResultSets open at a given time, which as a result prevents me from making multiple queries simultaneously. The essential problem is...
    ResultSet rs = statement.execute( "SELECT * FROM table");
    if (rs.next())
        ResultSet srs = statement.execute( "SELECT * FROM table2");
        rs.getInt("id");
    }...Yields a NullPointerException on line 5. If I am correct in my understanding, this is due to a ResultSet closing when it's statement is used a second time.
    My best guess to solving this problem is to create a pool of statement objects (which would essentially be a number of connections to the DB), and then use the first open statement object (or a newly created one) to run a particular query... however this seems rather sloppy. Not to mention that, offhand, I'm not even sure if I can have multiple connections open to the DB at the same time. Is there any better way to run multiple queries at the same time with JDBC?
    Thanks in advance for any help.
    -Jess

    That's actually what I thought at first as well... given that a NPE is generally thrown along the lines of null.getMethod() however there is no null anywhere in my code, only a closed ResultSet... which returns an NPE on using a get method. For example:
    //our import
    import java.util.*;
    import java.sql.*;
    import javax.swing.JComponent.*;
    public class Server
            public static void main( String args[] ) throws Exception
                    try
                            //register driver
                            Class.forName("com.mysql.jdbc.Driver");
                            //location of database (including string to register unicode as utf-8
                            String dbUrl = "jdbc:mysql://localhost:1111/db_name?requireSSL=false&useUnicode=true&characterEncoding=UTF-8";
                            //create connection object
                            Connection mysqlConnection = DriverManager.getConnection(dbUrl,"username","password");
                            //autocommit
                            mysqlConnection.setAutoCommit(true);
                            //log information
                            System.out.println("Connected. Connection=" + mysqlConnection);
                            Statement mysqlStatement = mysqlConnection.createStatement();
                            mysqlStatement.execute("SELECT * FROM mud_index_players");
                            ResultSet rs = mysqlStatement.getResultSet();
                            if (rs.next())
                                    System.out.prinlnt("getInt() is " + rs.getInt("id"));
                                    mysqlStatement.execute("SELECT * FROM mud_table_stats");
                                    ResultSet rs2 = mysqlStatement.getResultSet();
                                    System.out.println("Now it's " + rs.getInt("id"));
                    catch ( ClassNotFoundException cnfe )
                            cnfe.printStackTrace();
                    catch ( Exception e )
                            e.printStackTrace();
    }Yields:
    Connected. Connection=com.mysql.jdbc.Connection@329f3d
    getInt() is 1
    java.lang.NullPointerException
            at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:575)
            at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:930)
            at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2507)
            at Server.main(Server.java:34)Where line 34 in Server.main is System.out.println("Now it's " + rs.getInt("id"));Thanks again for all your help!
    -Jess
    Message was edited by:
    [email protected]
    (Was missing some code tags)

  • I have a problem with JDBC Realm in Tomcat/Oracle/Win XP

    I have a problem with JDBC Realm in Tomcat.
    I have attached my server.xml file located in the
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\server.xml
    The Problem is that when I login I get the user name and password prompt but it does not resolve.
    When I enter in the tomcat-users.xml password with memory realm uncommented it works fine.
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml
    Is there a cache or something I need to reset for the JDBC Realm to work?
    I have attached my tables and contents as well...
    Did I miss something????
    Thanks
    Phil
    server.xml
    <Server port="8005" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
    <!-- Global JNDI resources -->
    <GlobalNamingResources>
    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    </GlobalNamingResources>
    <!-- Define the Tomcat Stand-Alone Service -->
    <Service name="Catalina">
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector
    port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"
    enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Catalina" defaultHost="localhost">
    <!--
    <Realm className="org.apache.catalina.realm.MemoryRealm" />
    -->
    <Realm className="org.apache.catalina.realm.JDBCRealm"
    driverName="oracle.jdbc.driver.OracleDriver"
    connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
    connectionName="testName" connectionPassword="testPass"
    userTable="users"
    userNameCol="user_name"
    userCredCol="user_pass"
    userRoleTable="user_roles"
    roleNameCol="role_name" />
    <!-- Define the default virtual host
    Note: XML Schema validation will not work with Xerces 2.2.
    -->
    <Host name="localhost" appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    </Host>
    </Engine>
    </Service>
    </Server>
    Tables
    create table users
    user_name varchar(15) not null primary key,
    user_pass varchar(15) not null
    create table roles
    role_name varchar(15) not null primary key
    create table user_roles
    user_name varchar(15) not null,
    role_name varchar(15) not null,
    primary key( user_name, role_name )
    select * from users;
    ----------------------+
    | user_name | user_pass |
    ----------------------+
    | tomcat | tomcat |
    | user1 | tomcat |
    | user2 | tomcat |
    | user3 | tomcat |
    ----------------------+
    select * from roles;
    | role_name |
    | tomcat |
    | role1 |
    select * from user_roles;
    -----------------------+
    | role_name | user_name |
    -----------------------+
    | tomcat | user1 |
    | role1 | user2 |
    | tomcat | tomcat |
    | role1 | tomcat |
    -----------------------+

    Jan 2, 2008 11:49:35 AM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8080
    Jan 2, 2008 11:49:35 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 734 ms
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
    Jan 2, 2008 11:49:35 AM org.apache.catalina.realm.JDBCRealm start
    SEVERE: Exception opening database connection
    java.sql.SQLException: oracle.jdbc.driver.OracleDriver
         at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:684)
         at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:758)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1004)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
         at org.apache.catalina.core.StandardService.start(StandardService.java:450)
         at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardHost start
    INFO: XML validation disabled
    Jan 2, 2008 11:49:36 AM org.apache.catalina.core.StandardContext resourcesStart

  • Can't connect to external Oracle DB with JDBC connector

    Hello guys,
    I had failed to connect to connect external Oracle  via JDBC connector .
    Could you please help me to resolve the problem ?
    Backgroud:
    We need to connect the external Oracle DB with JDBC connector, because BI need to connect to the target Oracle. If the JDBC connector suceed, BI will create a UD which use the datasource
    we create in Visual admin to connect to the external Oracle DB.
    Environment:
    Our EP version is NW04S SP17 , OS is AIX .
    The target Oracle DB version is 10g(10.1.0.2.0, 64bi).
    Configuration procedure :
    1. Import Oracle driver "ojdbc14.jar" and create new driver which named "Oracle "  under
    JDBC Connector ->Run time ->Driver  in Visual Admin.
    2. Create datasource "Mydatasource" under JDBC Connector ->Run time ->Data Source,
    Name : Mydatasource
    Driver Name : Oracle
    JDBC version: 2.0(with XA support)
    JDBC compliant:
    Object Factory :oracle.jdbc.pool.OracleDataSourceFactory
    DataSource Type: ConnectionPoolDataSource
    *CPDS class name :oracle.jdbc.pool.OracleConnectionPoolDataSource
    Additional:
    Additional Properties:
    DatabaseName:LPAR8TEST
    DriverName:oracle.jdbc.OracleDriver
    Password: *****
    PortNumber:1521
    ServerName: 10.1.16.208
    URL :jdbc:oracel:[email protected]:1521:LPAR8TEST
    User:IMPL
    Connectoin Pool:
    Initial Connectons: 1                                         Expiration:  (check)
    Maximum Connections: 25                                  Connection Lifetime :600
    Maximum time wait of connection : 60                  Cleanup Thread : 200
    Default Connectoin Isolaton :Default
    SQL Engine:
    Open SQL
    3.Create Connector :
       Copy the standard connector :SDK_JDBC to SDK_JDBC_Oracle,
      Resource Adopter:
      Loader References:
      Add "libray:Oracle" .
    Managed Connection Factory:
    Configuration Property:
    DriverName:oracle.jdbc.OracleDriver
    Password: ****
    User:IMPL
    URL: jdbc:oracle:[email protected]:1521:LPAR8TEST
    All fo my configuration had been listed.
    And I had created JCO RFC : JT-BIDEV_PORTAL_BD1 , and created RFC connection with SM59 in BI.
    Please give me some suggesiton.
    Thanks.
    Louis

    When I try to start datasoure "Mydatasource" , it display error, error detail:
    java.rmi.RemoteException: com.sap.engine.services.dbpool.exceptions.BaseRemoteException: Error during start of application "sap.com/Mydatasource". [id = StartupError]
         at com.sap.engine.services.dbpool.deploy.DataSourceManagerImpl.startApplication(DataSourceManagerImpl.java:608)
    Caused by: java.rmi.RemoteException: Error occurred while starting application in whole cluster and wait.; nested exception is:
         com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Clusterwide exception: server ID 3128050:com.sap.engine.services.dbpool.exceptions.BaseDeploymentException: Cannot start DataSource "CGNPC".
         at com.sap.engine.services.dbpool.deploy.ContainerImpl.startDataSource(ContainerImpl.java:1549)
    Caused by: com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
         at com.sap.engine.services.dbpool.spi.CPManagedConnectionFactoryImpl.createManagedConnection(CPManagedConnectionFactoryImpl.java:198)
    Caused by: java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
    Caused by: com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Clusterwide exception: server ID 3128050:com.sap.engine.services.dbpool.exceptions.BaseDeploymentException: Cannot start DataSource "Mydatasource".
         at com.sap.engine.services.dbpool.deploy.ContainerImpl.startDataSource(ContainerImpl.java:1549)
    Caused by: com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
         at com.sap.engine.services.dbpool.spi.CPManagedConnectionFactoryImpl.createManagedConnection(CPManagedConnectionFactoryImpl.java:198)
    Caused by: java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
              u2026.
    When I try to test JDBC with URL : http://jt-pldev:50000/TestJDBC_Web/TestJDBCPage.jsp,
    First I choose connection name "SDK_JDBC_Oracle" .
    If I click "Check Connectons", it display :
    500   Internal Server Error
    SAP J2EE Engine/7.00
      Application error occurred during request processing.
      Details:
      java.lang.NoClassDefFoundError: com.sap.ip.bi.sdk.dac.connector.odbo.impl.Connection (initialization failure)
    Exception id: [001A64A86F2C006B000004C40010302A000469C74E86A096]
    If I click "Slecton Connection", it display:
    500   Internal Server Error
    SAP J2EE Engine/7.00
      Application error occurred during request processing.
      Details:
      com.sap.engine.frame.core.load.SAPNoClassDefFoundError: javax.resource.Referenceable
    Exception id: [001A64A86F2C0063000004C00010302A000469C74FA2BB59]

Maybe you are looking for

  • Confirmation control key issue

    Hi EXPERTS I would like to know under what circumstances can the confirmation control key be included in the line item of a PO after GRN is done. I am faced with a scenario where the GR of the line item of a PO is done  and their is a confirmation co

  • PRD Account hit at the GR reversal (102 movement type)

    Dear Experts' At the time of Goods reversal through 102 movement type, system automatically hit PRD account and it set off with freight clearing a/c. Why PRD a/c will hit at the time of reversal? Thnaks Suman Mukherjee MM Consultant

  • Premiere Pro CS5.x  - major lack of tutorials/documentation

    Seriously...the Adobe Classroom in Book of CS5 is the only book available? It's a bad book too, since it just wants you to follow all kind of 1,2,3 steps without explaining anything, not to mention that I can't stand doing those kind of spoon-fed les

  • Problem in configuring SAML

    Hi All, I installed SAP NetWeaver Application Server, Release Java EE 5 Engine(Trail and Preview version) in Windows Server 2003 Enterpise Edition. To configure SSO between Netweaver and a product from a third party vendor, I am required to configure

  • What do I need to do to get my new CS6 to read my 5D Marklll raw photos?

    What do I need to do to get my new cs6 to read my 5D Marklll raw photos?