JDBC getConnection

hi,
from some time I try to get a connection with a database for a standalone program on my computer using JDBC but I am not able to finish my purpose... and I am looking for for some help.
I had a connection to an Microsoft access database with the ODBC bridge but I never could get connection by any driver of JDBC.
I tried with some products but recently I am using Interbas of Borland.
I am using a Windows XP Oprating System.
I wite the follow code:
static public Connection makeDataBaseConnectionWithInterbase(){ 
Connection dbconn = null;
String url = "jdbc:interbase://localhost/G:\\Java\\employee.gdb";
// String url = "jdbc:interbase://ZORRO/G:/Java/employee.gdb";
// String url = "jdbc:interbase://loopback/G:/Java/employee.gdb";
try {       
Class.forName("interbase.interclient.Driver");
} catch ( ClassNotFoundException cnfex ) {  
// cnfex.printStackTrace();
System.out.println("getCause = " + cnfex.getCause());
System.out.println("getMessage = " + cnfex.getMessage());
try {
Driver driver = DriverManager.getDriver(url);
System.out.println("driver = " + driver.toString());
dbconn = DriverManager.getConnection(url,"sysdba","masterkey");
} catch ( SQLException cnfex ) {  
cnfex.printStackTrace();
System.out.println("Eccezione getCause = " + cnfex.getCause());
return dbconn ;
I give the classpath to interbase driver by command line writing:
path.. java -cp pathInterbase\interclient.jar; myProgram(.class)
I know the name of the driver with this line of output:
driver = interbase.interclient.Driver@b8df17
But after this I get a message indicating that the connection failed and that is the message:
java.sql.SQLException: interbase.interclient.IBException: [interclient][interbas
e]Unable to complete network request to host "java.net.ConnectException: Connect
ion refused: connect".
I hope someone could help me...
Thank you tonyMrsangelo

hello Saish,
You are right, I don't know the concepts and the procedure to work with server databases... becauose I am acustomed to work only with standalone programs and never I worked with server databases, so surely my problem is that I miss this knowledge
That is why I don't know the concepts that are behind the use of server database.
Could you inform me shortly what are the procedures when I want to work with server databases and where to found good informations about the basic concepts to use them in the applications client/server,
and also what is the difference in working between client/server database and standalone databases ?
P.S. I try to run the same database using interclient driver on NetBeans too, having the same problem that I said before...
thank you very much for your fast answer and help
please excuse my bad English.... it is not my mother language
tonyMrsangelo

Similar Messages

  • Why JDBC getConnection null? what is the problem?

    i have been using one class as thus clause:
    public java.sql.Connection getConnection(){
    String url = "jdbc:oracle:thin:@192.168.0.142:1521:test8152";
    java.sql.Connection con =null;
    java.sql.Statement stmt =null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = java.sql.DriverManager.getConnection(url,"conn","connection");
    } catch(Exception ex) { }
    return con;
    this method has been used normal in several instance for a long time, the oracle is all 816 enterprise, both for nt or linux or solaris.
    however, while i install a new oracle for linux on redhat6.2 which purchased recently, 816ee, i can not connect to it from other computers by this class, although i can connect to it by net8.sqlplus from other . nevertheless, i can connect to it in local computer by the same class with the same driver as classes12.zip; even if i use the drivers, which containd in the $ORACLE_home/jdbc/, the one is classes111.zip, the results is the same.
    the error message is the object do not exist, once i add the global service name, such as test8152.my_domain, the new message is 'refused connection'.
    thanks for your tips.
    null

    I had the same problem on this. The Linux Version of Oracle 8i seems have bugs on jdbc driver classes111.zip and classes12.zip ???
    I faced the same situation !!
    Do you find any other solution? It seems Oracle 8i oci/jdbc driver only support jdk 1.1.X . I am looking for oci/jdbc driver for 1.2. BUT I can not find it inside Oracle website ?!
    Do you find any ?
    Tommy Yang ( [email protected] )

  • JTA setRollbackOnly() w/ JDBC getConnection()

    I don't know if this belongs in the JTA forum or the JDBC forum, so please let me know if this is in the wrong place.
    The enlistResource() method in JTA will throw a RollbackException when trying to enlist a resource after setRollbackOnly() is called. Should the JDBC driver or connection pool pass this exception to the user?
    What I am seeing, in a certain implementation of a connection pool, is getConnection() throwing a SQLException when the enlistResource() throws RollbackException. I would expect the pool to handle the RollbackException and still return a connection, but I could be wrong.
    It makes sense to me that the transaction manager should still allow resources to be enlisted even if the TX status is STATUS_MARKED_ROLLBACK. If the TM should allow enlistment then I see no reason why the pool shouldn't return a connection instead of throwing a SQLException.
    Can anyone confirm this for me, or shed some light on the topic?
    -Andy

    Hi,
    The rollback exception can happen outside the responsibility of the JTA transaction manager (namely in the underlying JDBC database). It indicates that the database has decided to time out, for instance.
    The only way that both the JTA and the connection pool can find out in that case is by a failure such as this one.
    The only (well, straightforward) way to hide this would be to re-submit all previous work to the JDBC data source but in a NEW series of interactions through a new connection. This would require that the connection pool be aware of application-level logic and caches it in the transaction. In addition, since resubmission of previous SQL statements may yield different results the second time, it would jeopardize transactional correctness (serializability) of work done in other data sources.
    So, in a nutshell: the current situation is the most practical one (but maybe not for the end-user).
    Hope that helps,
    Guy
    http://www.atomikos.com

  • Jdbc hangs on first connection only

    We are running a number of java applications against an Oracle 11g database. The applications are all running on disk-less machines. We are seeing weird behaviour where the first connection, and only the first connection for each application hangs.
    We even see this for sqldeveloper, if you start sqldeveloper and try to make a connection, it sits there with the bar going back and forth until you click cancel, at which point every connection you attempt to make after that is fine.
    We are pretty sure this has to be a problem with JDBC running on a disk-less machine. We have some ODBC applications that run fine on these disk-less machines and we can run the java applications fine on a machine with a disk that has the same architecture as the one without.
    We have tried to turn on JDBC logging by using the ojdbc5_g.jar and setting oracle.jdbc.Trace=true, but have had no success, we have also tried doing it programatically by setting DriverManager.setLogger() and setting it to System.out, but haven't seen anything new.
    We are using the oracle:thin driver and are running on red hat 5.0 with Java 1.5 and a 64 bit architecture, against Oracle 11g . Does anyone have any thoughts on what is going on?
    Edited by: user538801 on Aug 11, 2009 12:15 PM

    We found it, it was a pretty obscure issue. The JDBC getConnection() method makes a call to the random number generator. This call hangs due to the system entropy being 0 on the disk-less blades, when the JVM starts up it waits on the first call to the random number generator for the system entropy to get above a certain threshold which it doesn't do.
    The solution was to use a different random number generator, by default the JVM uses/dev/random which requires sufficient entropy to seed the first call, we changed it to /dev/urandom by setting java.security.egd which is slightly less random, but does not hang on the first call.

  • Getting stuck on isClosed()

    I can't figure out for the life of me why this would be occurring. I call the open statement, and it runs the query without any issues what so ever. It gets to the this.resultSet.last() and tries to operate, but it gets stuck. I stepped inside of the this.resultSet.last() method, and found out that it's getting stuck specifically on the this.jdbc.getConnection().isClosed(). It runs just fine when this.jdbc.getConnection().isClosed() gets called in teh open, but comes to a dead stop right when it hits the same line in last(). After a certain amount of time passes, it eventually throws an Outofmemory exception. Any one happen to have an idea of what would or could be causing this? Any and all information would be useful. Thanks.
    public synchronized boolean open() {         try         {             if (this.jdbc instanceof MRxJDBC)             {                 if (this.jdbc.getConnection() instanceof java.sql.Connection)                 {                     if (!this.jdbc.getConnection().isClosed())                     {                         this.sql = "SELECT * FROM fills";                         this.preparedStatement = this.jdbc.getConnection().prepareStatement(this.sql,                                 ResultSet.TYPE_SCROLL_INSENSITIVE,                                 ResultSet.CONCUR_READ_ONLY);                         this.resultSet = this.preparedStatement.executeQuery();                         this.resultSet.last();                         this.count = this.resultSet.getRow();                         this.resultSet.beforeFirst();                         return true;                     }                     this.debug("open()", "", "The connection is not open", "");                     return false;                 }                 this.debug("open())", "", "No sql connection", "");                 return false;             }             this.debug("open()", "", "The MRXJDBC as not been instantiated.", "");         } catch (Exception ex)         {             ex.printStackTrace();             this.debug("open()", "", ex.getMessage(), "");             return false;         }         return true;     } public synchronized boolean last() {         try {             if (this.jdbc instanceof MRxJDBC) {                 if (this.jdbc.getConnection() instanceof java.sql.Connection) {                     if (!this.jdbc.getConnection().isClosed()) { //stuck right here. Pulls connection back NP, calls isClosed(), gets stuck                         if (this.resultSet instanceof ResultSet) {                             if (this.resultSet.last()) {                                 this.assign();                                 this.debug("last()", "Record "+this.resultSet.getRow()+" of "+this.count+" returned.", "", "");                                                return true;                             }                             this.debug("last()", "", "No records returned.", "");                                            return false;                         }                         this.debug("last()", "", "No results returned.", "");                                        return false;                     }                     this.debug("last()", "", "The connection is not open", "");                                    return false;                 }                 this.debug("last()", "", "No sql connection", "");                                return false;             }             this.debug("last()", "", "The MRXJDBC as not been instantiated.", "");                            return false;         } catch (Exception ex) {             this.debug("last()", "", ex.toString(), "");                            return false;         }     }
    Edited by: SabinsAura on Oct 8, 2009 7:28 AM

    At least tidy up that horrible nested method. Try this:
    public synchronized boolean last() {
       try {
          if (!(jdbc instanceof MRxJDBC)) {
             debug("last()", "", "The MRXJDBC as not been instantiated.", "");               
             return false;
          if (!(jdbc.getConnection() instanceof java.sql.Connection)) {
             debug("last()", "", "No sql connection", "");               
             return false;
          if (jdbc.getConnection().isClosed()) {
             debug("last()", "", "The connection is not open", "");               
             return false;
          if (!(resultSet instanceof ResultSet)) {
             debug("last()", "", "No results returned.", "");               
             return false;
          if (!resultSet.last()) {
             debug("last()", "", "No records returned.", "");               
             return false;
          assign();
          debug("last()", "Record "+resultSet.getRow()+" of "+count+" returned.", "", "");               
          return true;
       } catch (Exception ex) {
          debug("last()", "", ex.toString(), "");               
          return false;
    }What is "MRXJDBC" and are you sure it doesn't do pooling? Are you absolutely certain that the jdbc connection you pass in is the same as the jdbc field that you access in the above code?

  • Broadcasters: fix for those getting stuck on "Getting Playlist"

    Hello!
    My buddies and I launched recently a Webradio and we wanted to be listed on iTunes Radio Directory. We submitted our infos to [email protected] and we got listed.
    The problem was that nobody could listen to us: while playing the radio there was a "Getting Playlist" ("Récupération de la liste de lecture" in french) hanging and nothing else.
    We fixed this by changing our icecast 2 mount point from /radio.mp3 to /radio and submit back the adress to itunesradio for an update (it better to submit an .m3u link)
    Tadam ! It worked ! I guess itunes were confused by the .mp3, expecting a MP3 header and getting a http one.
    I did not see any solution for this problem so... let's share!
    Greetings from Bora Bora

    At least tidy up that horrible nested method. Try this:
    public synchronized boolean last() {
       try {
          if (!(jdbc instanceof MRxJDBC)) {
             debug("last()", "", "The MRXJDBC as not been instantiated.", "");               
             return false;
          if (!(jdbc.getConnection() instanceof java.sql.Connection)) {
             debug("last()", "", "No sql connection", "");               
             return false;
          if (jdbc.getConnection().isClosed()) {
             debug("last()", "", "The connection is not open", "");               
             return false;
          if (!(resultSet instanceof ResultSet)) {
             debug("last()", "", "No results returned.", "");               
             return false;
          if (!resultSet.last()) {
             debug("last()", "", "No records returned.", "");               
             return false;
          assign();
          debug("last()", "Record "+resultSet.getRow()+" of "+count+" returned.", "", "");               
          return true;
       } catch (Exception ex) {
          debug("last()", "", ex.toString(), "");               
          return false;
    }What is "MRXJDBC" and are you sure it doesn't do pooling? Are you absolutely certain that the jdbc connection you pass in is the same as the jdbc field that you access in the above code?

  • 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

  • JDBC x getConnection

    I�m using eclipse and when I was using the jdbc.odbc.jdbcodbcDriver a message error said that the driver was not found.
    Now I have downloaded the sql driver....and I did:
    public void stabilishConection()
              try
                   Class.forName("com.mysql.jdbc.Driver");
                   Connection con = DriverManager.getConnection("jdbc:myBase", "", "");
              catch(Exception e)
                   e.printStackTrace();
         }The message that appears is: no suitable driver at java.sql.DriverManager.getConnection(Unknown Source)
    I have set the classpath correctly....
    I�m a begginer and I�m just trying to create my first program..but I�m trying this for a long time and it�s not working...
    Do I have to create a dataBase file before running the program??

    I really don�t know what�s going on...but after I
    read the tutorial....
    The part that teachs how to connect doesn�t give any
    further niformation....
    I don�t have a mysql database on my machine...
    ...as I told before I�m a begginer in this subject...Okay let's try again.
    In order to use JDBC you need all of the following.
    1) A relational database system.
    2) A database.
    3) A JDBC driver that will connect to the above.
    You only have the driver. That's a problem. You are trying to connect to something that doesn't exist so we need to get that solved first.
    What OS are you running? I am asking because you need to use a database and if you are running Windows and have Access than that will be easiest.
    Please let me know what OS you are running and if you have Access.

  • Teradata connection error in jdbc -- DriverManager.getConnection()

    I have issue while connecting to teradata DB from a sampel jave jdbc code.
    the code is as below.
    String url="jdbc:teradata://10.33.22.27/AMRROCD";
    Class.forName("com.teradata.jdbc.TeraDriver");
    Properties x = new Properties();
    x.put("user","user123");
    x.put("password","pwd123");
    Connection con = DriverManager.getConnection (url, x);--> i am getting error at this line as
    GSSException: Failure unspecified at GSS-API level (Mechanism level: UserFile parameter null)
    at com.teradata.tdgss.jtdgss.TdgssParseXml.<init>(DashoA1*..)
    at com.teradata.tdgss.jtdgss.TdgssConfigApi.<init>(DashoA1*..)
    at com.teradata.tdgss.jtdgss.TdgssManager.<init>(DashoA1*..)
    at com.teradata.tdgss.jtdgss.TdgssManager.getInstance(DashoA1*..)
    at com.teradata.jdbc.jdbc.GenericTeraEncrypt.getGSSM(GenericTeraEncrypt.java:583)
    at com.teradata.jdbc.jdbc.GenericTeraEncrypt.getConfig(GenericTeraEncrypt.java:601)
    at com.teradata.jdbc.jdbc.GenericTeraEncrypt.getUserNameForOid(GenericTeraEncrypt.java:694)
    at com.teradata.jdbc.AuthMechanism.<init>(AuthMechanism.java:50)
    at com.teradata.jdbc.jdbc.GenericInitDBConfigState.action(GenericInitDBConfigState.java:105)
    at com.teradata.jdbc.jdbc.GenericLogonController.run(GenericLogonController.java:49)
    at com.teradata.jdbc.jdbc_4.TDSession.<init>(TDSession.java:195)
    at com.teradata.jdbc.jdbc_3.ifjdbc_4.TeraLocalConnection.<init>(TeraLocalConnection.java:94)
    at com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:55)
    at com.teradata.jdbc.TeraDriver.doConnect(TeraDriver.java:216)
    at com.teradata.jdbc.TeraDriver.connect(TeraDriver.java:149)
    at java.sql.DriverManager.getConnection(DriverManager.java:512)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at dbValidation.main(dbValidation.java:25)
    Error java.lang.NullPointerException
    could anybody have an idea on this , its urgent for me to solve this.
    I am able to execute the code in windows OS . this error is occourring in UNIX system

    You'd have to pursue Teradata for support/help with their JDBC driver. This has nothing
    to do with Oracle though...

  • JDBC: java.lang.ExceptionInInitializerError on DriverManager.getConnection

    I've been developing an app on Linux and had the JDBC connector working fine, connecting to mySQL.
    Now when I try to run it on Solaris 2.8 with Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05), I get the following error trying a connect...
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mysql.jdbc.Connection.<init>(Connection.java:1175)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:193)
    at ps.DataCollector.getData(DataCollector.java:46)
    at ps.PacketSchedular.main(PacketSchedular.java:30)
    Caused by: java.lang.RuntimeException: Unable to initialize character set mapping tables
    at com.mysql.jdbc.CharsetMapping.<clinit>(CharsetMapping.java:73)
    ... 6 more
    my java file is ....
    public class DataCollector {
    private String database = "oui";
    private String user = "user";
    private String passwd = "password";
    private int portNum = 3306;
    public DataCollector () {
    public void getData() {
    Statement stmt = null;
    Connection conn = null;
    ResultSet rs = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/" + database + "?port=" + portNum + "&user=" + user + "&password=" + passwd + "&autoReconnect=false");
    etc
    etc
    I'm using the mysql connector 'mysql-connector-java-3.1.8-bin.jar' and i've also downgraded to an earlier release which had no positive effect.
    Google (unusually) has given me no hints!
    Any suggestions as to what may be causing this?
    Thanks

    I can connect to the server locally and also telnet to port 3306 and get a response!
    telnet localhost 3306Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    4
    5.0.18LIVU'`/hA,I*7tf~jx>iu2
    I use this same server with Perl every day (although Perl is using a socket to connect).
    I've searched pretty much everywhere for a fix - but to no avail.
    Thanks

  • Using JDBC to write a DAT file with delimiters to a database

    Hi Everybody
    I am new to JDBC and i am trying out some small applications: I downloaded this small program and tried to compile it and and I got the following errors: ( I have MySql installed). I have to set the classpath for the driver. But I am not sure why I am gettting the NullPointerException though)
    I will be very gratefull to your help. Thanks a lot..
    Loading JDBC Driver -> oracle.jdbc.driver.OracleDriver
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at us.ilango.WriteFileToTable.<init>(WriteFileToTable.java:69)
         at us.ilango.WriteFileToTable.main(WriteFileToTable.java:367)
    java.lang.NullPointerException
         at us.ilango.WriteFileToTable.createTable(WriteFileToTable.java:97)
         at us.ilango.WriteFileToTable.main(WriteFileToTable.java:368)
    Exception in thread "main"
    the Program is as follows:
    package us.ilango;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.text.NumberFormat;
    import java.text.ParseException;
    * The following class provides an example of how to read a simple text file
    * of records and then insert them into a table in a database. A text file
    * named Employee.txt will contain employee records to be inserted into the
    * following table:
    *      SQL> desc emp
    *      Name              Null?    Type
    *      EMP_ID              NOT NULL NUMBER
    *      DEPT_ID                      NUMBER
    *      NAME                NOT NULL VARCHAR2(30)
    *      DATE_OF_BIRTH       NOT NULL DATE
    *      DATE_OF_HIRE        NOT NULL DATE
    *      MONTHLY_SALARY      NOT NULL NUMBER(15,2)
    *      POSITION            NOT NULL VARCHAR2(100)
    *      EXTENSION                    NUMBER
    *      OFFICE_LOCATION              VARCHAR2(100)
    * NOTE: This example will provide and call a method that creates the EMP
    *       table. The name of the method is called createTable() and is called
    *       from the main() method.
    public class WriteFileToTable {
        final static String driverClass    = "oracle.jdbc.driver.OracleDriver";
        final static String connectionURL  = "jdbc:oracle:thin:@localhost:1521:CUSTDB";
        final static String userID         = "scott";
        final static String userPassword   = "tiger";
        final static String inputFileName  = "Employee.txt";
        final static String TABLE_NAME     = "EMP";
        final static String DELIM          = ",";
        Connection   con                   = null;
         * Construct a WriteFileToTable object. This constructor will create an
         * Oracle database connection.
        public WriteFileToTable() {
            try {
                System.out.print("  Loading JDBC Driver  -> " + driverClass + "\n");
                Class.forName(driverClass).newInstance();
                System.out.print("  Connecting to        -> " + connectionURL + "\n");
                this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
                System.out.print("  Connected as         -> " + userID + "\n");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to create the initial EMP table. Before attempting to create
         * the table, this method will first try to drop the table.
        public void createTable() {
            Statement stmt = null;
            try {
                stmt = con.createStatement();
                System.out.print("  Dropping Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
                System.out.print("    - Dropped Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                System.out.print("    - Table " + TABLE_NAME + " did not exist.\n");
            try {
                stmt = con.createStatement();
                System.out.print("  Creating Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("CREATE TABLE emp (" +
                                 "    emp_id           NUMBER NOT NULL " +
                                 "  , dept_id          NUMBER " +
                                 "  , name             VARCHAR2(30)  NOT NULL " +
                                 "  , date_of_birth    DATE          NOT NULL " +
                                 "  , date_of_hire     DATE          NOT NULL " +
                                 "  , monthly_salary   NUMBER(15,2)  NOT NULL " +
                                 "  , position         VARCHAR2(100) NOT NULL " +
                                 "  , extension        NUMBER " +
                                 "  , office_location  VARCHAR2(100))");
                System.out.print("    - Created Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to read records from Employee.txt file then write the records
         * to an Oracle table within the database named "EMP".
        public void performLoadWrite() {
            Statement stmt          = null;
            int       insertResults = 0;
            StringTokenizer st = null;
            String  emp_id;
            String  dept_id;
            String  name;
            String  date_of_birth;
            String  date_of_hire;
            String  monthly_salary;
            String  position;
            String  extension;
            String  office_location;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Create FileReader Object for file: " + inputFileName + "...\n");
                FileReader inputFileReader = new FileReader(inputFileName);
                System.out.print("  Create BufferedReader Object for FileReader Object...\n");
                BufferedReader inputStream   = new BufferedReader(inputFileReader);
                String inLine = null;
                while ((inLine = inputStream.readLine()) != null) {
                    st = new StringTokenizer(inLine, DELIM);
                    emp_id   = st.nextToken();
                    dept_id  = st.nextToken();
                    name     = st.nextToken();
                    date_of_birth = st.nextToken();
                    date_of_hire = st.nextToken();
                    monthly_salary = st.nextToken();
                    position = st.nextToken();
                    extension = st.nextToken();
                    office_location = st.nextToken();
                    System.out.print("  Inserting value for [" + name + "]\n");
                    insertResults = stmt.executeUpdate(
                            "INSERT INTO " + TABLE_NAME + " VALUES (" +
                                      emp_id +
                            "  ,  " + dept_id +
                            "  , '" + name + "'" +
                            "  , '" + date_of_birth + "'" +
                            "  , '" + date_of_hire + "'" +
                            "  ,  " + monthly_salary +
                            "  , '" + position + "'" +
                            "  ,  " + extension +
                            "  , '" + office_location + "')");
                    System.out.print("    " + insertResults + " row created.\n");
                System.out.print("  Commiting Transaction...\n");
                con.commit();
                System.out.print("  Closing inputString...\n");
                inputStream.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
         * Method used to query records from the database table EMP. This method
         * can be used to verify all records have been correctly loaded from the
         * example text file "Employee.txt".
        public void queryRecords() {
            Statement stmt           = null;
            ResultSet rset           = null;
            int       deleteResults  = 0;
            int       rowNumber      = 0;
            int     emp_id;
            int     dept_id;
            String  name;
            String  date_of_birth;
            Date    date_of_birth_p;
            String  date_of_hire;
            Date    date_of_hire_p;
            float   monthly_salary;
            String  position;
            int     extension;
            String  office_location;
            try {
                SimpleDateFormat formatter      = new SimpleDateFormat("yyyy-MM-dd");
                NumberFormat     defaultFormat  =     NumberFormat.getCurrencyInstance();
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Opening query for table: " + TABLE_NAME + "...\n");
                rset = stmt.executeQuery ("SELECT * FROM emp ORDER BY emp_id");
                while (rset.next ()) {
                    rowNumber = rset.getRow();
                    emp_id = rset.getInt(1);
                    if ( rset.wasNull() )   {emp_id = -1;}
                    dept_id = rset.getInt(2);
                    if ( rset.wasNull() )   {dept_id = -1;}
                    name = rset.getString(3);
                    if ( rset.wasNull() )   {name = "<null>";}
                    date_of_birth = rset.getString(4);
                    if ( rset.wasNull() ) {date_of_birth = "1900-01-01";}
                    try {
                        date_of_birth_p = formatter.parse(date_of_birth);
                    } catch (ParseException e) {
                        date_of_birth_p = new Date(0);
                    date_of_hire = rset.getString(5);
                    if ( rset.wasNull() ) {date_of_hire = "1900-01-01";}
                    try {
                        date_of_hire_p = formatter.parse(date_of_hire);
                    } catch (ParseException e) {
                        date_of_hire_p = new Date(0);
                    monthly_salary = rset.getFloat(6);
                    if ( rset.wasNull() ) {monthly_salary = 0;}
                    position = rset.getString(7);
                    if ( rset.wasNull() ) {position = "<null>";}
                    extension = rset.getInt(8);
                    if ( rset.wasNull() )   {extension = -1;}
                    office_location = rset.getString(9);
                    if ( rset.wasNull() ) {office_location = "<null>";}
                    System.out.print(
                        "\n" +
                        "  RESULTS -> [R" + rowNumber + "] " + "\n" +
                        "      Employee ID     : " + emp_id + "\n" +
                        "      Department ID   : " + dept_id + "\n" +
                        "      Employee Name   : " + name + "\n" +
                        "      D.O.B.          : " + date_of_birth_p + "\n" +
                        "      Date of Hire    : " + date_of_hire_p + "\n" +
                        "      Monthly Salary  : " + defaultFormat.format(monthly_salary) + "\n" +
                        "      Position        : " + position + "\n" +
                        "      Extension       : x" + extension + "\n" +
                        "      Office Location : " + office_location +
                        "\n");
                System.out.print("  Closing ResultSet...\n");
                rset.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Close down Oracle connection.
        public void closeConnection() {
            try {
                System.out.print("  Closing Connection...\n");
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Sole entry point to the class and application.
         * @param args Array of String arguments.
         * @exception java.lang.InterruptedException
         *            Thrown from the Thread class.
        public static void main(String[] args)
                throws java.lang.InterruptedException {
            WriteFileToTable runExample = new WriteFileToTable();
            runExample.createTable();
            runExample.performLoadWrite();
            runExample.queryRecords();
            runExample.closeConnection();
        }

    Hi
    Thanks a lot. I ran the program with the MySql driver as follows:
    The errors are as follows: I will ttry to place the Driver in the Classpath. As far as I know the driver has been specified correctly this time.
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at us.ilango.WriteAntennas.<init>(WriteAntennas.java:41)
         at us.ilango.WriteAntennas.main(WriteAntennas.java:377)
    java.lang.NullPointerException
         at us.ilango.WriteAntennas.createTable(WriteAntennas.java:70)
         at us.ilango.WriteAntennas.main(WriteAntennas.java:378)
    Exception in thread "main" Loading JDBC Driver -> com.mysql.jdbc.Driver
    The program is as follows:
    package us.ilango;
    * @author ilango
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    public class WriteAntennas {
        final static String driverClass    = "com.mysql.jdbc.Driver";
        final static String connectionURL  = "jdbc:mysql://localhost/test2";
        final static String userID         = "brian";
        final static String userPassword   = " ";
        final static String inputFileName  = "CO.DAT";
        final static String TABLE_NAME     = "CELL";
        final static String DELIM          = "|";
        Connection   con                   = null;
        public WriteAntennas() {
            try {
                System.out.print("  Loading JDBC Driver  -> " + driverClass + "\n");
                Class.forName(driverClass).newInstance();
                System.out.print("  Connecting to        -> " + connectionURL + "\n");
                this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
                System.out.print("  Connected as         -> " + userID + "\n");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to create the initial EMP table. Before attempting to create
         * the table, this method will first try to drop the table.
        public void createTable() {
            Statement stmt=null;
            try {
                stmt = con.createStatement();
                System.out.print("  Dropping Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
                System.out.print("    - Dropped Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                System.out.print("    - Table " + TABLE_NAME + " did not exist.\n");
            try {
                stmt = con.createStatement();
                System.out.print("  Creating Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("create table TOWER_PUBACC_CO (" +
         "record_type               char(2)              null" +
         ", content_indicator         char(3)              null" +
         ", file_number               char(8)              null" +
         ", registration_number       char(7)              null" +
         ", unique_system_identifier  long(9,0)         not null" +
         ", coordinate_type           char(1)              not null" +
         ",latitude_degrees          int                  null" +
         ",latitude_minutes          int                  null" +
         ",latitude_seconds          int(4,1)         null" +
         ",latitude_direction        char(1)              null" +
         ",latitude_total_seconds    int(8,1)         null" +
         ",longitude_degrees         int                  null" +
         ",longitude_minutes         int                  null" +
         ",longitude_seconds         int(4,1)         null" +
         ",longitude_direction       char(1)              null" +
         ",longitude_total_seconds   int(8,1)         null)" );
                System.out.print("   created Table...\n");
                System.out.print("  closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public void performLoadWrite() {
            Statement stmt          = null;
            int       insertResults = 0;
            StringTokenizer st = null;
            String record_type ;
            String  content_indicator;
            String file_number ;
            String registration_number;
             String unique_system_identifier ;
            String coordinate_type;
            String latitude_degrees;
            String  latitude_minutes;
            String latitude_seconds;
            String latitude_direction;
            String latitude_total_seconds;
            String longitude_degrees;
           String longitude_minutes;
           String longitude_seconds;
           String longitude_direction;
           String longitude_total_seconds;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Create FileReader Object for file: " + inputFileName + "...\n");
                FileReader inputFileReader = new FileReader(inputFileName);
                System.out.print("  Create BufferedReader Object for FileReader Object...\n");
                BufferedReader inputStream   = new BufferedReader(inputFileReader);
                String inLine = null;
                while ((inLine = inputStream.readLine()) != null) {
                    st = new StringTokenizer(inLine, DELIM);
                    record_type   = st.nextToken();
                   content_indicator = st.nextToken();
                    file_number    = st.nextToken();
                    registration_number = st.nextToken();
                    unique_system_identifier = st.nextToken();
                   coordinate_type =st.nextToken();
                   latitude_degrees  = st.nextToken();
                   latitude_minutes = st.nextToken();
                    latitude_seconds=st.nextToken();
                   latitude_direction = st.nextToken();
                    latitude_total_seconds =st.nextToken();
                    longitude_degrees= st.nextToken();
                    longitude_minutes = st.nextToken();
                    longitude_seconds = st.nextToken();
                    longitude_direction=st.nextToken();
                    longitude_total_seconds =st.nextToken();
                    System.out.print("  Inserting value for [" + unique_system_identifier + "]\n");
                    insertResults = stmt.executeUpdate(
                            "INSERT INTO " + TABLE_NAME + " VALUES (" +
                                      record_type +
                            "  ,  " + content_indicator +
                            "  , '" + file_number + "'" +
                            "  , '" + registration_number + "'" +
                            "  , '" + unique_system_identifier + "'" +
                            "  ,  " + coordinate_type + "'" +
                            "  , '" + latitude_degrees + "'" +
                            "  ,  " + latitude_minutes + "'" +
                            "  , '" + latitude_seconds + "'" +
                            "  , '" + latitude_direction + "'" +
                            "  , '" + latitude_total_seconds + "'" +
                           "  , '" + longitude_minutes + "'" +
                           "  , '" + longitude_seconds + "'" +
                          "  , '" + longitude_direction + "'" +
                           "  , '" + longitude_total_seconds + "')");
                    System.out.print("    " + insertResults + " row created.\n");
                System.out.print("  Commiting Transaction...\n");
                con.commit();
                System.out.print("  Closing inputString...\n");
                inputStream.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
        public void queryRecords() {
            Statement stmt           = null;
            ResultSet rset           = null;
            int       deleteResults  = 0;
            int       rowNumber      = 0;
            String   record_type;
            String   content_indicator;
            String  file_number;
            String registration_number ;
            long  unique_system_identifier;
            String coordinate_type ;
            int   latitude_degrees ;
            int latitude_minutes ;
            int latitude_seconds;
            String latitude_direction;
            int  latitude_total_seconds;
            int     longitude_degrees;
             int longitude_minutes;
               int     longitude_seconds;
                 String longitude_direction;
           int  longitude_total_seconds;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Opening query for table: " + TABLE_NAME + "...\n");
                rset = stmt.executeQuery ("SELECT * FROM cell ORDER BY unique_system_identifier");
                while (rset.next ()) {
                    rowNumber = rset.getRow();
                    unique_system_identifier = rset.getInt (1);
                    if ( rset.wasNull() )   {unique_system_identifier = -1;}
                    record_type = rset.getString (2);
                    if ( rset.wasNull() )   {record_type = "<null>";}
                    content_indicator = rset.getString(3);
                    if ( rset.wasNull() )   {content_indicator = "<null>";}
                    file_number = rset.getString(4);
                    if ( rset.wasNull() ) {file_number = "<null>";}
                    registration_number = rset.getString(5);
                    if ( rset.wasNull() ) {registration_number = "<null>";}
                    coordinate_type = rset.getString(6);
                    if ( rset.wasNull() )   {coordinate_type = "<null>";}
                    latitude_degrees = rset.getInt(7);
                    if ( rset.wasNull() ) {latitude_degrees = 1;}
    latitude_minutes = rset.getInt(8);
                    if ( rset.wasNull() ) {latitude_minutes = 1;}
    latitude_seconds = rset.getInt(9);
                    if ( rset.wasNull() ) {latitude_seconds = 1;}
    latitude_direction = rset.getString(10);
                    if ( rset.wasNull() ) {latitude_direction = "<null>";}
    latitude_total_seconds = rset.getInt(11);
                    if ( rset.wasNull() ) {latitude_total_seconds = 1;}
    longitude_degrees = rset.getInt(12);
                    if ( rset.wasNull() ) {longitude_degrees = 1;}
    longitude_minutes = rset.getInt(13);
                    if ( rset.wasNull() ) {longitude_minutes = 1;}
    longitude_seconds = rset.getInt(14);
                    if ( rset.wasNull() ) {longitude_seconds = 1;}
    longitude_direction = rset.getString(15);
                    if ( rset.wasNull() ) {longitude_direction = "<null>";}
    longitude_total_seconds = rset.getInt(16);
                    if ( rset.wasNull() ) {longitude_total_seconds = 1;}
                    System.out.print(
                        "\n" +
                        "  RESULTS -> [R" + rowNumber + "] " + "\n" +
                        "  Unique_System_Identifier         : " + unique_system_identifier  + "\n" +
                        "  Record_type     : " + record_type   + "\n" +
                        "  Content_Indicator      : " + content_indicator   + "\n" +
                        "  Registration_Number              : " + registration_number   + "\n" +
                        "  File_Number        : " +  file_number  + "\n" +
                        "  Coordinate_Type     : " + coordinate_type  + "\n" +
                        "  Latitude_Degrees          : " + latitude_degrees + "\n" +
                        "  Latitude_Minutes          : " + latitude_minutes + "\n" +
                        "  Latitude_Seconds           : " + latitude_seconds + "\n" +
                        " Latitude_Direction            : " + latitude_direction + "\n" +
                        "  Latitude_Total_Seconds           : " + latitude_total_seconds + "\n" +
                        "  Longitude_Degrees           : " + longitude_degrees + "\n" +
                        "  longitude_minutes           : " + longitude_minutes + "\n" +
                        "  Longitude_Seconds           : " + longitude_seconds + "\n" +
                       "     longitude_direction        : " + longitude_direction + "\n" +
                       "  Longitude_Total_Seconds           : " + longitude_total_seconds +
                       "\n");
                System.out.print("  Closing ResultSet...\n");
                rset.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public void closeConnection() {
            try {
                System.out.print("  Closing Connection...\n");
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public static void main(String[] args)
                throws java.lang.InterruptedException {
            WriteAntennas runJob = new WriteAntennas();
            runJob.createTable();
            runJob.performLoadWrite();
            runJob.queryRecords();
            runJob.closeConnection();
    }

  • Can't connect a servlet to a mysql database (jdbc)

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    public class LoginServletJDBC extends HttpServlet{
         public void doGet(HttpServletRequest request,HttpServletResponse response)
         throws ServletException,IOException{
              sendLoginForm(response,false);     }
         public void sendLoginForm(HttpServletResponse response,boolean error)
         throws ServletException,IOException{
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
              out.println("<html><head>");
              out.println("<title>Login</title>");
              out.println("</head>");
              out.println("<body>");
              out.println("<center>");
              if(error)
                   out.println("<b>Failed login. Please try again</b>");
              out.println("<br><br>");
              out.println("<h2>Login page</h2>");
              out.println("<br>Please enter your username and password");
              out.println("<br><br>");
              out.println("<form method=post>");
              out.println("<table>");
              out.println("<tr>");
              out.println("<td>Username : </td>");
              out.println("<td><input type=text name=userName></td>");
              out.println("</tr>");
              out.println("<tr>");
              out.println("<td>Password : </td>");
              out.println("<td><input type=password name=password></td>");
              out.println("</tr>");
              out.println("<tr>");
              out.println("<td align=right colspan=3>");
              out.println("<input type=submit value=Login></td>");
              out.println("</tr>");
              out.println("</table>");
              out.println("</form>");
              out.println("</center>");
              out.println("</body></html>");
    public void doPost(HttpServletRequest request,HttpServletResponse response)
         throws ServletException,IOException{
              String userName = request.getParameter("userName");
              String password = request.getParameter("password");
              if(login(userName,password)){
                   RequestDispatcher rd = request.getRequestDispatcher("AnotherServlet");
                   rd.forward(request,response);
              else{
                   sendLoginForm(response,true);
         boolean login(String userName,String password){
              try{
                   String url = "jdbc:mysql://localhost:3306/Users";
                   Class.forName("com.mysql.jdbc.Driver");
                   Connection con = DriverManager.getConnection(url,"root","");
                   //System.out.println("got connection");
                   Statement s = con.createStatement();
                   String sql = "select userName from Users where userName='"+userName+"and password='"+password+"';";
                   ResultSet rs = s.executeQuery(sql);
                   if(rs.next()){
                        rs.close();
                        s.close();
                        con.close();
                        return true;
                   rs.close();
                   s.close();
                   con.close();
              catch(ClassNotFoundException e){
                   System.out.println(e.toString());
              catch(SQLException e){
                   System.out.println(e.toString());
              catch(Exception e){
                   System.out.println(e.toString());
              return false;
    }so ...
    here i'm trying to connect to Users mysql database (i use Tomcat 4.1 and mysql servers and clients 4.0.1-alpha)
    where is the problem ? when i run this servlet (http://localhost:8080/example/servlet/LoginServletJDBC ) it works ;
    BUT when i type an username and a password (any user&pass) my servlet doesn't connect to the database (become a infinite loop without output ; i mean no any errors and exceptions)
    i try other think : i changed the database with unexisting database and the result was that i was expected (Unknow database 'unexistingdatabase' )
    what i miss ?
    please... can anyone help me...
    thank`s in advance

    The wireless security setting that the Actiontec modem/router is using may be different...and not compatible....than the setting that the Comcast product was using.
    If you think that might the case, and you have the time to troubleshoot......
    Temporarily, turn off the wireless security on the Actiontec modem/router
    Reset an AirPort Express back to default settings, then see if it will connect using no security and allow an Internet connection when you do the Ethernet port test in the post above again.
    If the AirPort Express cannot connect correctly using no security on the wireless network.....then it is a no brainer to know that it will never connect when security is enabled.  So, if the AirPort will not connect using no security, you may have an incompatibility issue between the Actiontec and Apple products.
    However, if the AirPort Express connects OK with no security, then this tells you that you will need to use a different setting for security on the Actiontec...the same that the Comcast router was using before.....so the Express will have a better chance of connecting.
    That setting would be something like WPA/WPA2 Personal, or the same setting stated another way would be WPA-PSK-TKIP.

  • Adding to a Collection using JDBC

    I'm trying to add to a Collection via JDBC but have had no luck with getting the ResultSet into the Collection and would be grateful for some pointers in the right direction in the while (rs.next()) block:
    public void getMembers(BwGroup group) throws CalFacadeException {
         Class.forName("com.mysql.jdbc.Driver");
         String url = "jdbc:mysql://localhost/loginlist";
         Connection conn = null;
         Collection<BwPrincipal> ms = new TreeSet<BwPrincipal>();
          try {
             conn = DriverManager.getConnection(url, "user", "pword");
             PreparedStatement ps = conn.prepareStatement("SELECT * FROM list WHERE list='" + group +"'");
             ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                   BwPrincipal = new bp(rs.getString(1));
                   ms = addAll(bp);
               group.setGroupMembers(ms);
               rs.close();
               ps.close();
               } catch (Exception e){
                e.printStackTrace();
               } finally {
             if (conn != null) {
            conn.close();
        }I'm getting errors regarding incompatible types for the BwPrincipal line and addAll being an unfound symbol (though I had thought that it was a method to add to Collections). If I try to call BwPrincipal as BwPrincipal bp = new bp(rs.getString(1)); then the addAll error disappears but the programme cannot see BwPrincipal as a class. I feel as if I'm going around in circles at the moment.

    BaroqueThoughts wrote:
    As you say, I'm trying to call something along the lines of
    ms= rs.getString(1);but get an incompatible string back. The reading that I had done suggested addAll but I've probably misunderstood in trying to get this to work. If I try
    ms.add(rs)then the compiler doesn't like the add method (add cannot be applied to java.sql.ResultSet)Well it can't. Why did you try that, though? To be honest, if you can't figure this out yet, JDBC is probably a step too far at the moment. Re-visit the basics, because you clearly don't understand them yet, and you'll struggle forever if you carry on down this path as-is

  • OpenSQLException: JDBC driver not supported?

    Hi @ all,
    I need to connect to a DataSource with the WebAS 7 via SQLJ. As I try to connect to it with the SQL Engine set to "Vendor SQL" I get:
    "The given connection "com.sap.engine.services.dbpool.cci.ConnectionHandle" is not an Open SQL connection"
    As I try to get a connection to the dataSource via SQLJ with SQL Engine set to "Open SQL" or "Native SQL", I get the following Exception:
    ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: com.sap.sql.log.OpenSQLException: JDBC driver not supported for MS_SQL_SERVER database.
    How can I get the SQLJ- Support?
    Kind regards,
    Uwe
    Message was edited by:
            Uwe Kunath

    Hi Uwe, all,
    for using Native SQL/JDBC or Open SQL/JDBC, the database itself and the JDBC driver must be recognized as being in the supported set. The answer to that depends on what you mean in detail by "Web AS 7". Roughly speaking, it should be the JDBC driver released by Microsoft.
    Open SQL/SQLJ is only available with a Open SQL/JDBC data source. Hence, there is no way around using Open SQL/JDBC.
    Now, Open SQL/JDBC and Open SQL/SQLJ both requires tables (and other database objects) to be deployed via the Open SQL for Java Dictionary. Up to and including WebAS Java 7.1, the Open SQL/Dictionary supports deployment to the system database, i.e. the database (and schema) used by the installed server itself.
    Given the above, the JDBC driver for a Open SQL/JDBC data source must already be present, because it must be the driver used by the server itself. When defining data sources, it is referred to as "system driver".
    This leaves us with a Open SQL/JDBC data source to the system schema. You can then also consider to establish a data source alias to the server's system datasource.
    Hope this helps. Best Regards, Dietamr

  • Declarative Transactions, Session Beans & JDBC

    Hi (this is really a newbie question),
    If I executed an SQL Update statement in a Stateless Session Bean via JDBC,
    is my call to the database enlisted in the container transaction
    automatically? (Of course, I am assuming the correct TxRequired settings
    are set on the deployment descriptors for the Session Bean.)
    Asked in another way, how does JDBC "talk" to the EJB container to let it
    know that it is being called within a Transactional Context and that all
    activities with the database should then be enlisted in a transaction
    automatically? Where does this "smartness" come in? Or does this not happen
    at all - do I have to "obtain" the JDBC connection object from the EJB
    container instead of writing directly to JDBC?
    Thanks in advance,
    Abdullah Kauchali

    Correct.
    I'd also recommend (where possible), doing the DataSource JNDI lookup in
    your setSessionContext method and storing it away in a member variable.
    There's usually no reason to do it on every method call.
    -- Rob
    Abdullah Kauchali wrote:
    Okay,
    After some investigations, this is what I've learned:
    1. To get automatic transactional enlistment (in a distributed tx), you
    have to make your EJB container aware of the JDBC datasource (viz. you have
    to create a Transactional DataSource). This is done by creating necessary
    entries in a configuration XML file so that the container can connect to the
    JDBC datasource when fired-up;
    2. You then only create your Connection object via a reference (JNDI to be
    exact) to the connection object and NOT directly with JDBC (this was my
    confusion in fact). Something like this:
    //obtain the conduit to the JNDI resource manager factory
    javax.sql.DataSource objDS = (javax.sql.DataSource)
    context.lookup("~some jndi
    reference~");
    //now get the connection object - notice no "javax" but "java"
    java.sql.Connection objCon = objDS.getConnection();
    3. By doing 2. above you are actually using a "Resource Manager Connection
    Factory" to get your Connection object for subsequent SQL Updates;
    4. As long as your JDBC driver supports the javax.sql.DataSource interface
    and provided Transactional Context is propagated from any root call to your
    worker Session Bean, you get automatic transaction enlistment of the SQL
    Updates with your EJB container;
    Please correct me if I have concluded wrongly,
    Regards
    Abdullah
    "Abdullah Kauchali" <ak@ak> wrote in message
    news:[email protected]...
    Hi (this is really a newbie question),
    If I executed an SQL Update statement in a Stateless Session Bean viaJDBC,
    is my call to the database enlisted in the container transaction
    automatically? (Of course, I am assuming the correct TxRequired settings
    are set on the deployment descriptors for the Session Bean.)
    Asked in another way, how does JDBC "talk" to the EJB container to let it
    know that it is being called within a Transactional Context and that all
    activities with the database should then be enlisted in a transaction
    automatically? Where does this "smartness" come in? Or does this nothappen
    at all - do I have to "obtain" the JDBC connection object from the EJB
    container instead of writing directly to JDBC?
    Thanks in advance,
    Abdullah Kauchali

Maybe you are looking for

  • Getting the name of the host that the forms server is running on?

    Hi I have a very simple question, but can't find a simple answer at the moment. Is there something like GET_APPLICATION_PROPERTY within forms 10g that I can use to return the hostname of the machine that the form is running on (i.e. the name of the a

  • Optical Drive Sound

    When I pick up my curent Macbook 13'' (mid-2010). I hear the optical drive spin a few times then stop. I am wondering if this is normal?

  • Orphan folder?  Help!

    I have create a business folder containing many folders. When I sign into reports, I see all the folders in that business folder except one! How can I get that folder to appear. It's weird. I have gone into tool/manage folders....nothing. I have gone

  • I can't see Guitar Rig inside of Logic

    I'm trying to get GR working in Logic Express. I did the customized install for the Audio Units setup. When I go to Modify the guitar track and select Stereo-> Audio Units - I don't see Guitar Rig FX in there. Also if I try to load a GarageBand proje

  • J2ee Server stopped with exit code = -2

    Hi, We have an Xi system on Windows 2000 server. and when starting the SAP on the system SAP instance is up and running but in the java instance it shows that the J2ee server status is stopped with exit code= -2. And the jcontrol.exe is showing some