Database connectivity without using Class.forName()

Hi,
Can anyone please tell how we can connect to a database without in java without using the Class.forName() method , and then how the database driver gets loaded.
Regards,
Tanmoy

Hi,
I recently wrote code that connects to a database without using Class.forName() in order to be compatible with Microsoft's JVM. I read about it here:
http://www.idssoftware.com/faq-e.html#E1
Basically, you create a new Driver object and use its connect method.
Here's what my particular code ended up being:
String url = "jdbc:mysql://localhost:3306/test?user=root&password=mypass";
Driver drv = new org.gjt.mm.mysql.Driver();
Connection con = drv.connect(url,null);

Similar Messages

  • Database refresh without using RMAN duplicate

    Hi All,
    I am planning to refresh my test instance to a PIT using RMAN backups from PROD. I would like to know the process without connecting to PROD database and without using RMAN duplicate command.
    Thanks.

    imran khan wrote:
    Can you please show the demo first then we will discuss on it more.. what if the folk wants to refresh it ten times then we have to change the database name ten times using NID?
    >Can you please show the demo first then we will discuss on it more.. what if the folk wants to refresh it ten times then we have to change the database name ten times using NID?
    1) You use nid only to change the dbid.
    2) I have done this type of cloning much more than 50 times.
    3) As Iordan Iotzov pointed out, in 11gR2 you can run DUPLICATE database without being connected to the PROD
    Here is a sample code of how to do it assuming both file system are the same:
    # -- RMAN Restore to another server
    rman <<EOF2
    CONNECT TARGET /;
    STARTUP NOMOUNT
    SET DBID 987654321;
    CONNECT CATALOG rman/rman@rcvcat
    RUN {
        SET UNTIL SEQUENCE=5678 THREAD=1;
        ALLOCATE CHANNEL ch0 DEVICE TYPE DISK;
        RESTORE CONTROLFILE;
    ALTER DATABASE MOUNT;
    RUN
      SET UNTIL SEQUENCE=5678 THREAD=1;
      ALLOCATE CHANNEL ch0 DEVICE TYPE DISK;
      ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
      ALLOCATE CHANNEL ch2 DEVICE TYPE DISK;
      ALLOCATE CHANNEL ch3 DEVICE TYPE DISK;
      RESTORE DATABASE;
      RECOVER DATABASE;
    EXIT;
    EOF2:p

  • How to use class.forName

    I am trying to use Class.forName() from a string which is passed to me as argument.
    Class batchClass = Class.forName(args[1]);
    A jar file contains the class file for the string received above and I have this jar file in the manifest of my executable jar.
    I get a class not found exception when I run my executable jar
    Can some body give pointers..what could possibly be the issue.
    The jar file is in my classpath
    run script
    #!/bin/csh
    java -jar -DDBPROVIDER=NO -DDBUS_ROOT=$DBUS_ROOT -DVTNAME=$VTNAME ./jar/IntraDayDepotPositionBatch.jar MagellanStart IntraDayDepotPositionBatch INPUTFILE LOGFILE
    Exception
    Magellan program starting - program class IntraDayDepotPositionBatch
    Cannot find program class - IntraDayDepotPositionBatch
    IntraDayDepotPositionBatch
    java.lang.ClassNotFoundException: IntraDayDepotPositionBatch
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at com.db.mmrepo.app.IntraDayDepotPositionBatch.MagellanStart.main(Unknown Source)
    Thanks for your time and feedback on this

    actually i tried both...with package name and without package name..
    nothing worked...
    my manifest file also contains the path to the package..so does the classpath

  • Why use Class.forName() ?

    Why is it always adviced to use Class.forName( nameOfTheDriver ). Why dont we simply import the driver via the import statement ?
    Please note that this topic is part of a bigger topic I published in Java programming about difficulties I had importing driver. See:
    http://forums.java.sun.com/thread.jsp?forum=31&thread=147534
    for more details.

    Because using an import statement only tells the compiler about the driver. Class.forName() actually loads the driver when the program runs, which is what you want to happen.

  • How to create an object of our own class by using Class.forName()??

    how to create an object of our own class by using Class.forName()??
    plzz anser my qustion soon..

    Class.forName does not create an object. It returns a reference to the Class object that describes the metadata for the class in question--what methods and fields it has, etc.
    To create an object--regardless of whether it's your class or some other class--you could call newInstance on the Class object returned from Class.forName, BUT only if that class has a no-arg constructor that you want to call.
    Class<MyClass> clazz = Class.forName("com.mycompany.MyClass");
    MyClass mine = clazz.newInstance();If you want to use a constructor that takes parameters, you'll have to use java.lang.reflect.Constructor.
    Google for java reflection tutorial for more details.
    BUT reflection is often abused, and often employe when not needed. Why is it that you think you need this?

  • Add a new record in database table without using table maintance generator

    Hi Expart ,
                  Plz. tell me how to add new record in database table without using table maintance ganerator ....give me one ex.
    Regards
    Bhabani

    Hi,
    The other way to safely handle the modification of tables is through is by programs that can be done with SE38 or SE80.
    To insert into database table we use INSERT statement :
    1. To insert a single line into a database table, use the following:
    INSERT INTO <target> VALUES <wa>.
    INSERT <target> FROM <wa>.
    2. To insert a several lines into a database table, use the following:
    INSERT <target> FROM TABLE <itaba>.
    Or even we can use MODIFY statementas this single statement is used to insert as well as update the records of database table.
    MODIFY <target> FROM <wa>.
    or MODIFY <target> FROM TABLE <itab>.
    thanx.
    Edited by: Dhanashri Pawar on Sep 10, 2008 12:25 PM
    Edited by: Dhanashri Pawar on Sep 10, 2008 12:30 PM

  • How to display icons on selection screen ,without using classes.

    Hi Experts,
    How can we display icons on the selection-screen ..?
    one of the methods i heard frm my frnds was to use                   ->cl_gui_picture_viewer
    but as a begginer i am not tht comfortable with classes .So is there a way around to display icons on my selection screen without using classes .
    Thanx in Advance,
    Regards ,
    Rajesh .

    Hi,
    here a short example:
    REPORT Z_TEST2.
    TABLES: SSCRFIELDS.   "Felder auf Selektionsbildern
    INCLUDE .
    SELECTION-SCREEN: BEGIN OF BLOCK A01 WITH FRAME TITLE MELDUNG1.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 10(04) T_ICON.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFSD.
    PARAMETERS:       P_AUFSD  AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFCO.
    PARAMETERS:       P_AUFCO  AS CHECKBOX DEFAULT ' '.
    SELECTION-SCREEN: PUSHBUTTON 45(04) PB01 USER-COMMAND SALL.
    SELECTION-SCREEN: PUSHBUTTON 50(04) PB02 USER-COMMAND DALL.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFCS.
    PARAMETERS:       P_AUFCS  AS CHECKBOX DEFAULT ' '.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFPP.
    PARAMETERS:       P_AUFPP  AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN: PUSHBUTTON 45(15) PB03 USER-COMMAND INIT.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: PUSHBUTTON 45(15) PB04 USER-COMMAND ONLI.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: END   OF BLOCK A01.
    AT SELECTION-SCREEN.
      IF SSCRFIELDS-UCOMM = 'SALL'. "alle selektieren
        P_AUFSD = 'X'.
        P_AUFCO = 'X'.
        P_AUFCS = 'X'.
        P_AUFPP = 'X'.
      ENDIF.
      IF SSCRFIELDS-UCOMM = 'DALL'. "alle deselektieren
        P_AUFSD = ' '.
        P_AUFCO = ' '.
        P_AUFCS = ' '.
        P_AUFPP = ' '.
      ENDIF.
      IF SSCRFIELDS-UCOMM = 'INIT'. "initialisiern
        P_AUFSD = 'X'.
        P_AUFCO = ' '.
        P_AUFCS = ' '.
        P_AUFPP = 'X'.
      ENDIF.
    INITIALIZATION.
      MELDUNG1 = 'Datenbankselektion'.
      T_ICON   = ICON_PRINT.
      T_AUFSD  = 'Kundenauftrag'.
      T_AUFCO  = 'Innenauftrag'.
      T_AUFCS  = 'Serviceauftrag'.
      T_AUFPP  = 'Fertingungsauftrag'.
      PB01     = ICON_SELECT_ALL.
      PB02     = ICON_DESELECT_ALL.
      CONCATENATE ICON_REFRESH 'Initial' INTO PB03.
      CONCATENATE ICON_EXECUTE_OBJECT 'Ausführen' INTO PB04.
    START-OF-SELECTION.
    write: / 'Test'.
    END-OF-SELECTION.
    Regards, Dieter

  • Alv field with f4 help without using class

    Hi,
    Can any one give me a program of "Alv field with f4 help without using class".
    Thanking you in advance.

    hi
    <b>Linking F4 Help to Fields</b>
    For the last section, we will deal with linking F4 help to fields. It is easy. As usual, define, implement and register the event “onf4” at proper places in your code. For F4 help, you must register the fields whose F4 request will trigger the “onf4” event. For this you must prepare a table of type “LVC_T_F4” and register this table using the method “register_f4_for_fields”. While preparing table you must include a line for each field which will trigger F4 event. For each field in the structure;
    &#1048766; Pass the fieldname to ‘FIELDNAME’
    &#1048766; Set ‘REGISTER’ to make the field registered,
    &#1048766; Set ‘GETBEFORE’ to provide field content transport before F4 in editable mode
    &#1048766; Set ‘CHNGEAFTER’ to make the data changed after F4 in editable mode.
    DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE .
    lt_f4-fieldname = 'PRICE'.
    lt_f4-register = 'X' .
    lt_f4-getbefore = 'X' .
    APPEND lt_f4 .
    CALL METHOD gr_alvgrid->register_f4_for_fields
    EXPORTING
    it_f4 = lt_f4[] .
    Preparing table for the fields to be registered to trigger F4 event
    METHOD handle_on_f4 .
    PERFORM f4_help USING e_fieldname es_row_no .
    er_event_data->m_event_handled = 'X' .
    ENDMETHOD .
    A sample “onf4” method implementation
    Again, we set the attribute “er_event_data->m_event_handled” to prevent further processing of standard F4 help.
    regards
    Ravish
    <b>
    reward if useful</b>

  • ClassNotFoundException when using Class.forName(), thx

    in a study app, i try to use Class.forName() to load any class then get its properties (fields, methods etc. vs reflect).
    the (Frame based) app is in directory:
    c:\app\StudyApp.class
    there is a "Open class" button on the app, click the button, i use FileChooser to open any class file.
    i.e. open a class (assume it is not packaged)
    d:\dir\TheClass.class
    coding in StudyApp.java is:
    Class cls=Class.forName("TheClass");
    now a ClassNotFoundException throws when call Class.forName() above.
    it is easy to understand why throw the exception because i never tell where the class is. it is in directory
    d:\dir
    my question is: how to tell VM the directory.
    the directory d:\dir can not be applied to -classpath when run java.exe StudyApp, because the directory is random one at run-time.
    i tried to change System property (i.e. "java.class.path", 'user.dir" etc. none of them can fix the problem.
    thanks in advance for any help

    This probably does a lot more than you need:
    import java.util.*;
    import java.io.*;
    import java.util.jar.*;
    import java.lang.*;
    public class ClassFileFinder extends ClassLoader
         List cpath = new LinkedList();
         void addFile(File f) {
              if(f.isDirectory() || (f.isFile() && f.canRead() &&
                                          f.getName().endsWith(".jar")))
                   cpath.add(f);
         public byte[] classData(String className)  {
              String cname = className.replace('.', File.separatorChar) + ".class";
              Iterator it = cpath.iterator();
              while(it.hasNext()) {
                   File f = (File)it.next();
                   try {
                        if(f.isDirectory()) {
                             File cFile = new File(f, cname);
                             if(cFile.isFile()) {
                                  byte[] buf = new byte[(int)cFile.length()];
                                  InputStream in = new FileInputStream(cFile);
                                  int off  = 0, l;
                                  while((l = in.read(buf, off, buf.length - off)) > 0) {
                                       off += l;
                                       if(off >= buf.length) break;
                                  in.read(buf);
                                  in.close();
                                  return buf;
                        } else if (f.isFile()) {
                             JarFile jar = new JarFile(f);
                             JarEntry ent = jar.getJarEntry(cname);
                             if(ent != null) {
                                  byte[] buf = new byte[(int)ent.getSize()];
                                  int off = 0, l;
                                  InputStream in = jar.getInputStream(ent);
                                  while((l = in.read(buf, off, buf.length - off)) > 0) {
                                       off += l;
                                       if(off >= buf.length) break;
                                  in.close();
                                  return buf;
                   } catch (IOException e) {
              return null;          
         public Class findClass(String className) throws ClassNotFoundException{
              byte[] data = classData(className);
              if(data == null)
                   return getParent().loadClass(className);
              else
                   return defineClass(className,data,0, data.length);
    }Create an instance, Add directories and/or jar files with addFile then loadClass the class you want.

  • I can't set up gmail in my iPad 2. Keep on saying ' can't connect with SSL and ask me whether to connect without using SSL, then I press 'yes' and it said again IMAP is not working and tell me to see network connection and incoming mail server.

    I can't set up gmail in my iPad 2. Keep on saying ' can't connect with SSL and ask me whether to connect without using SSL, then I press 'yes' and it said again IMAP is not working and tell me to see network connection and incoming mail server. No idea how to do anymore. Already tried to figure out. But not work. Can anyone pls help me?

    Nope, doesn't pass verification. I get the spinner for a minute or so, then the alert about setting it up without SSL. Are you suggesting I disable Fetch and Push BEFORE I enter the account details? Because I never get past the account details screen, unless I choose "Set up without SSL" after the warning.

  • Why can't i use class.forName(str) ?

    Heys all i have this piece of code which is working fine:
    *try {*
    java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    *} catch (java.lang.ClassNotFoundException e) {*
    now the problem is that i was under the impression that i could use class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); but it wouldn't compile. does anyone know why is this so?

    Class.forName() says "call the static method forName() that is defined in java.lang.Class". It returns a reference to an instance of java.lang.Class.
    SomeClass.class is known as a class literal. It is not a member, not a field, not a method. It evaluates to a reference to an instance of java.lang.Class.
    You cannot do class.something().
    Edited by: jverd on Oct 26, 2010 9:46 AM

  • Instantiating object using Class.forName()

    What is the difference between instantiating using Class.forName() method and instantiating using the new operator?

    The difference is that you can use the new operator to instantiate an object, but you can't do it using Class.forName().
    But seriously folks...
    Presumably you're talking about Class.newInstance()--which often appears right on the heels of Class.forName().
    New gives you compile-time checks you don't get with Class.forName(). If it compiles with new, then you know the constructor in question exists on the class in question.
    With Class.newInstance() (and it's cousin (also called newInstance, I think) in the Constructor class), you can't be sure until you actually execute it whether that constructor even exists.
    New requires you to know the class at compile time. NewInstance lets you defer the specific class until runtime.
    New is simpler and more direct.
    (Did I just do your homwork for you? Hope not.)

  • How to use Forms Default Database Connection in java class

    When a form based application is started, a connection is made with underlying database. This is the Default (Primay) Database Connection.
    The problem is I have some of my business logic implemented in a java class. In this class I have to make a another connection with the same database. What I want to do is to use the original Database Connection in the java class. In this I may avoid the overhead of reconnection.
    Could anyone pls guide me in this way...

    you can't share the forms connection. Sorry :(

  • Database connecting problem using iPlanet Server

    hi experts,
    i am new begi to iPlanet server.
    before that i was using JWS2.0.
    simple servlet is working fine in iPlanet.
    when coming to database connectivity, there is error shown as
    "SQLException java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified "
    below is my servlet
    import javax.servlet.*;          
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class test1 extends HttpServlet
    Connection dbCon;
    Statement stat;
    public void init(ServletConfig config) throws javax.servlet.ServletException
    public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
    ResultSet rs;
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    dbCon = DriverManager.getConnection("jdbc:odbc:collegeodbc","","");
    stat = dbCon.createStatement();
    rs = stat.executeQuery("select * from degrees");
    rs.next();
    out.println(rs.getString(1));
    rs.close();
    catch(ClassNotFoundException ce)
    out.println("Class Not Found "+ce);
    catch(SQLException se)
    out.println("SQLException "+se);
    public void destroy()
    this same coding with void main() in system working fine.
    still that servlet working fine with JWS2.0 also, but not in iPlanet.
    any idea.
    Plz help experts
    thanks in adv.

    hi,
    yes u can avoid restarting the server after compiling a servlet
    just follow the following instruction
    go to \Netscape\Server4\https-admserv\config\contexts.properties
    and uncomment the following lines
    context.global.reloadInterval=1
    context.global.isModifiedCheckAggressive=true
    and do the same step for the following properties file in
    \Netscape\Server4\https-"ur machine name"\config\contexts.properties
    and u can avoid restarting the server after u compile a servlet

  • Which Database connectivity is used professionally in JSP/Servlet?

    Hi friends,
    Can you tell me which type of database connectivity is generally used in professional web-related projects.
    I mean to say,
    1) Class.forName method or
    2) context lookup using JNDI Data Source method.
    Also,
    I wonder how in shared hosting anybody writes their <Resource> tag inside TomcatRoot\conf\server.xml file.
    In my local Tomcat6 i can do that. But, in Live Shared hosting how to handle JNDI Datasource?
    ---Sujoy

    me_sujoy wrote:
    Hi friends,
    Can you tell me which type of database connectivity is generally used in professional web-related projects.
    I mean to say,
    1) Class.forName method or
    2) context lookup using JNDI Data Source method.By using a connection pool (usually the one provided by the server).
    >
    Also,
    I wonder how in shared hosting anybody writes their <Resource> tag inside TomcatRoot\conf\server.xml file.
    In my local Tomcat6 i can do that. But, in Live Shared hosting how to handle JNDI Datasource?Uhm, by using the context.xml. See the documentation for your Tomcat.

Maybe you are looking for

  • Getting errors just trying to download Mavericks wondering if I really should do it

    I'm reading of others having problems w Mavericks, although some say its fine. The reason that is pushing me is that I updated my iPad Mini to ios 7 & now when I try to open a Numbers file on it, it tells me if I open it, I will no longer be able to

  • Same code, different positioning

    Hello, I am a fairly new person to web design. I was working on a project for my uncle, and for some reason with the same code I got different results on different browsers. Here's what I mean: 1) Chrome 2) Mozilla #1 "read more..." is positioned hig

  • Album artwork screensaver screwed up my settings.

    alright a while back i put my screensaver as itunes album artwork. this has caused me some problems. the first is that every time i open my screen saver settings it just closes so i get this error message and i click reopen and it reopens i click on

  • Long field type data transfer

    hello I want to copy one table data into another table having long data type but it gives me error like SQL> insert into temp select * from temp1; insert into temp select * from temp1 ERROR at line 1: ORA-00997: illegal use of LONG datatype both of t

  • BPM Studio on Mac OS X

    Hi Has anyone successfully run BPM Studio 10R3 on Mac OS X (ideally Tiger 10.4)? Being an Eclipse-based, I am guessing it should be possible. Best regards Ben