How to use JDBC to connect Oracle databse

Hi
I try to connect the oracle databse by using JDBC. But I not sure whether is it correct or not because I learnt from the documentation provided by WWW.JAVA.SUN.
I have create a ODBC DSN file call TKS username/password : tem/manager
then I download the source code and enhance a bit as following :
import java.sql.*;
public class CreateCoffees
public static void main(String args[])
     String url = "jdbc:oracle:thin:tem/manager@(
     description=(address_list=(
     address=(protocol=tcp)
     (host=192.9.200.8)(port=1521)))(source_route=yes)
     (connect_data=(sid=tks)))";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
     catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try {
con = DriverManager.getConnection(url, "tem", "manager");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
     catch(SQLException ex)
     {  System.err.println("SQLException: " + ex.getMessage());
After that I saved the file as CreateCoffees.java and compiled it
D:\KLTAY\JAVA>javac CreateCoffees.java
CreateCoffees.java:6: unclosed string literal
String url = "jdbc:oracle:thin:tem/manager@(
^
CreateCoffees.java:10: unclosed string literal
(connect_data=(sid=tks)))";
^
CreateCoffees.java:30: cannot resolve symbol
symbol : variable con
location: class CreateCoffees
con = DriverManager.getConnection(url, "tem", "manager");
^
CreateCoffees.java:31: cannot resolve symbol
symbol : variable con
location: class CreateCoffees
stmt = con.createStatement();
^
CreateCoffees.java:34: cannot resolve symbol
symbol : variable con
location: class CreateCoffees
con.close();
^
5 errors
Please give some advise.Thanks
best regards,
Tay

     String url = "jdbc:oracle:thin:tem/manager@(
     description=(address_list=(
     address=(protocol=tcp)
     (host=192.9.200.8)(port=1521)))(source_route=yes)
     (connect_data=(sid=tks)))";
After that I saved the file as CreateCoffees.java and
compiled it
D:\KLTAY\JAVA>javac CreateCoffees.java
CreateCoffees.java:6: unclosed string literal
String url = "jdbc:oracle:thin:tem/manager@(
^
CreateCoffees.java:10: unclosed string literal
(connect_data=(sid=tks)))";
^I would suggest putting all code between the quotesj(") on one line and then attempting to recompile.

Similar Messages

  • How to use jdbc to connect oracle

    I want use jdbc direct to connect oracle database,and I
    want to use sun Company or oracle Company driver. how can I get driver and how do I write connection string?
    Deeply to wait your reply,thank you!

    The correct format would be jdbc:oracle:thin@server:port:sidTry "jdbc:oracle:thin:@192.168.84.20:1521:ORDB","ysys","fareast"and see what happens.
    Note that you two formats for the DriverManager.getConnection() method; if DriverManager.getConnection(db_url, username, password) doesn't work, try the other call with a fully-qualified database url:DriverManager.getConnection("jdbc:oracle:thin:ysys/[email protected]:1521:ORDB")The SID is the server ID that was given to the instance when the database was installed; default is ORCL, but may have been changed. Port default is 1521, but again, this may be different for your system.

  • How to use JDBC database connection in Solaris

    Hi all,
    I am new to Solaris and i want to create an application using JDBC database connection.
    I want a small piece of code, probably a login page code that verifies the username from a OpenOffice database (.odb) file. I am particular to know the driver name, etc. If possible give the code using JNDI loopkup.
    Thanks in advance,
    Parasou.

    Sure no problem.
    Please stand by while I do your work for you.

  • -How to use JDBC to connect the SQLServer and Oracle.

    Hi,
    I create a table in the WIP DB, I want to modify this table when use "PRE-START" activity in POD.
    SAPME version: 5.2.3.4     SDK:2.0    DB:SQL2005 and Oracle 10.2g
    SourceCode like below:
    public void execute(StartHookDTO dto) throws Exception {
              initServices();
              try{
                   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                   Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=SAPMEWIP", "sa" ,"sap12345");
                   conn.close();
              }catch(Exception e){
                   e.printStackTrace();
    Besides, I already setup the JDBC ClassPath in ConfigTool, but it gets somes error when executing.
    the error code like below:
    java.sql.SQLException: No suitable driver
    Please give me some support or a example, thank you so much!
    Br,
    Alex

    You probably want to use the WIP Datasource defined in JNDI.

  • How to use JDBC to connect informix database

    Dear all,
    I want my client application to connect informix database by using JDBC. The JDBC driver has been installed successfully in the client computer (Win2000). The informix 5.0 resides the a Unix server named "dbserver". The following is my java program.
    ========================
    import java.sql.*;
    import java.awt.event.*;
    public class Application1 {
    public static void main(String[] args) {
    Connection conn;
    try
    Class.forName("com.informix.jdbc.IfxDriver");
    catch (Exception e)
    System.out.println("Error "+e.getmessage());
    e.printStackTrace();
    return;
    System.out.println("It is ok");
    try
    conn = DriverManager.getConnection("jdbc:informix-sqli://dbserver:1526:INFORMIXSERVER=dbserver;username=test;password=******");
    catch (SQLException e)
    System.out.println("ERROR ."+e.getMessage());
    e.printStackTrace();
    return;
    System.out.println("All is fine");
    ===========================
    However, the error appears mentioning "Attempt to connect to database server (dbserver) failed." I don't know what the problem is because my informix database server is exactly "dbserver".
    Kindly need help from you guys. Thanks in advance.
    Kevin

    Hi,
    Plz try this (instead of 'username' use 'user') ...
    DriverManager.getConnection("jdbc:informix-sqli://dbserer:1526:INFORMIXSERVER=dbserver;user=test;password=*****");
    or this (pass the username and password as params)....
    DriverManager.getConnection( "jdbc:informix-sqli://dbserer:1526:INFORMIXSERVER=dbserver" , "test" , "*****" );
    Hope this helps
    ssa.
    >
    I want my client application to connect informix
    database by using JDBC. The JDBC driver has been
    installed successfully in the client computer
    (Win2000). The informix 5.0 resides the a Unix server
    named "dbserver". The following is my java program.
    ========================
    import java.sql.*;
    import java.awt.event.*;
    public class Application1 {
    public static void main(String[] args) {
    Connection conn;
    try
    Class.forName("com.informix.jdbc.IfxDriver");
    catch (Exception e)
    System.out.println("Error "+e.getmessage());
    e.printStackTrace();
    return;
    System.out.println("It is ok");
    try
    conn =
    onn =
    DriverManager.getConnection("jdbc:informix-sqli://dbser
    er:1526:INFORMIXSERVER=dbserver;username=test;password=
    catch (SQLException e)
    System.out.println("ERROR ."+e.getMessage());
    e.printStackTrace();
    return;
    System.out.println("All is fine");
    ===========================
    However, the error appears mentioning "Attempt to
    connect to database server (dbserver) failed." I don't
    know what the problem is because my informix database
    server is exactly "dbserver".
    Kindly need help from you guys. Thanks in advance.
    Kevin

  • How to use JDBC to connect to oracle7.3.4 on remote host

    I have written a small applet which runs fine on one host(Solaris
    box)using appletviewer. In this program I am trying to connect
    to oracle on another host and the program is working fine. The
    same applet is not working from a web page.
    can anyone help me out?
    giving error like netscape.security.AppletSecurity.exception
    and lot more exception
    null

    You are restricted by the Java security sandbox from connecting
    directly to another machine through the applet. You have to use
    a JDBC driver located on the web server machine. Please make
    sure you have installed this properly, as in appended a valid
    JDBC .jar archive to your CLASSPATH.
    Openlink Software has robust JDBC drivers that enable scrollable
    (rowset driven) cursors. You may be interested in checking out
    http://www.openlinksw.com for further info.
    Our latest JDBC drivers are found at
    ftp://ftp.openlinksw.com/pre-3.2/index.html
    (scroll down to the very bottom - Windows section - don't worry,
    they're platform independent!)
    Best regards
    BVReddy (guest) wrote:
    : I have written a small applet which runs fine on one host
    (Solaris
    : box)using appletviewer. In this program I am trying to
    connect
    : to oracle on another host and the program is working fine.
    The
    : same applet is not working from a web page.
    : can anyone help me out?
    : giving error like netscape.security.AppletSecurity.exception
    : and lot more exception
    null

  • How to use oci7 to connect oracle 7.1.6

    is that only need to change the String as "jdbc.oracle.oci8:" to
    "jdbc.oracle.oci7", it will search for oci native code by the jdbc driver?
    my using classes12.zip; and classes111.zip also available.
    which gentleman can help me?
    thanks
    fred

    String change alone will not help. Oracle connects to a remotely located database via its own netclient software which you must install. If the platform is same for client and database server, then you do not need netclient but you then have to keep listener running and set up Oracle home, Oracle_sid properly. You could test all these connectivity issues by using sqlplus. If that works well, everything is fine and you then just have to experiment with different connect string in your java prog. hope this helps??

  • How to use JDBC to connect Tomcat with database server?(Urgent!)

    I try to deploy the tomcat and make it connect with databaser server.
    I am using mysql connector J 3.0. I added the CLASSPATH of mysql-connector-java-3.0.7-stable-bin.jar in the tomcat.sh .
    I also add the web application in server.xml.
    When I start tomcat, I can see using Classpath including mysql-connector-java-3.0.7-stable-bin.jar .
    But when i browse my jsp including the jdbc, wait for a while, I get a message as following: Timeout on server localhost. My web server and database server is same computer.
    Could you tell me what's wrong?

    Did you check to see that the MySQL database was indeed up and running, and accepting connections when you started Tomcat? Did you make sure that your firewall permits connections to the database?
    Timeout errors generally occur when you send a request to a server and the server does nothing with it - i.e., it doesn't respond to it in any way. Most firewalls are configured this way. If I telnet to your machine and I get "connection refused", I know your machine exists and I can try hacking into it. If I telnet and get nothing at all, then I will either assume either there's no actual machine at that address or it's unresponsive.

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • How to use JDBC Lookup in PI 7.1 ?

    Hi,
    Please advise how to use JDBC lookup in message mapping PI 7.1 ? any reference link / document  ?
    I have followed this step below :
    1. Create the external definition for the database table.
    2. Use the external definition (table) in message mapping JDBC Lookup.
    But the target still "Yellow colour" meanint the mapping hasnot completed yet ? why ? and when i double click the JDBC lookup
    there some error message
    "No suitable parameter found; define new parameter of type 'Channel' first"
    Please advise.
    Thank You and Best Regards
    Fernand

    Hi Fernand,
    JDBC Lookup can be done in PI 7.1 using below mentioned steps :
    1) Create a communication channel between PI and the database to connect to database.
    2) Import the table data as External Definition.
    3) In message mapping where this lookup is to be used select JDBC Lookup under Conversions and map
    4) Double Click on JDBC Lookup
    5) Select parameter and a database table (imported as the external definition). All the elements of the table will appear in the middle column. Select and move the input parameters to the left side column and the output parameters to the right side column. Click OK. 
    6) Under message mapping go to signature tab and define the parameter as channel and category as JDBC Adapter Type. 
    7) Under Operation mapping define the parameter & associate it with parameter defined in Message Mapping.
    Thanks
    Amit

  • Is there any documentation on how to use JDBC in ALBPM?

    I'm trying to connect to a DB using DriverManager class.
    1) I've defined an externalResource of type SQL Database.
    2) When I execute the following code:
    //externalResourceURL is the URL of the SQL Database external resource created in 1), same for user and password
    con as java.sql.Connection = DriverManager.getConnection(arg1=externalResourceURL, arg2=user, arg3=password)
    3) I get the following error: This driver is locked for use with embedded applications.
    Is there any tutorial or documentation on how to use JDBC in ALBPM?
    Thanks in advance

    I don't know of any documentation off hand... but what are you trying to do? I haven't needed to to make a connection using the DriverClass....
    If you aren't using dynamicSQL... you can just catalog the database, and make direct sql calls (not recommended)... but if you catalog it, then just an INSERT command works... or UPDATE... etc
    logMessage "Starting insert."
    INSERT INTO MYTABLE(id, name) VALUES ("2", "kevin");
    logMessage "Finished insert."Check out the studio help under SQL Keywords for more info on that...
    HTH
    -Kevin

  • I want to use jdbc to connect MS SQL SERVER

    hi,
    I want to use jdbc to connect MS SQL SERVER,not the jdbc-odbc bridge.
    I download the driver from MS,deploy it,but when I connect the database such as:
    <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");%>
    <%String sConnStr="jdbc:microsoft:sqlserver://computer2000:1433";%>
    <%Connection conn=DriverManager.getConnection(sConnStr,"sa","123");%>
    <%Statement stmt=conn.createStatement();%>
    but it said
    javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    how can i work out this problem
    maybe my configure is wrong,please give me a successful sample configuration
    thanks a lot

    Hi,
    I am not sure where you have got the following code from
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    What happens here, is Java Runtime will search for the Class named:
    com.microsoft.jdbc.sqlserver.SQLServerDriver
    If this Class is not in the Runtime Classpath, it will throw the Error that you have got. Kindly get the proper driver as well as ensure that the Class is available in the Runtime Classpath.
    Thanks and regards,
    Pazhanikanthan. P

  • Junit : how to create JDBC URL connection

    hi folks,
    I am implementing JUnit in my application , for that I have seen srdemo application every thing is fine but i havent get how to configure JDBC URL connection 'SRServiceLocalTesting' ? can any body tell me how to do it.
    Thanks in advance
    Regards
    Pravin

    Hi,
    Have a look,
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/odi/odi_11g/odi_project_xml-to-table/odi_project_xml-to-table.htm
    Thanks,
    Guru

  • How to use java source in Oracle when select by sqlplus.

    How to use java source in Oracle when select by sqlplus.
    I can create java source in Oracle
    import java.util.*;
    import java.sql.*;
    import java.util.Date;
    public class TimeDate
         public static void main(String[] args)
    public String setDate(int i){
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(new Date((long)i*1000));
    System.out.println("Dateline: "
    + calendar.get(Calendar.HOUR_OF_DAY) + ":"
    + calendar.get(Calendar.MINUTE) + ":"
    + calendar.get(Calendar.SECOND) + "-"
    + calendar.get(Calendar.YEAR) + "/"
    + (calendar.get(Calendar.MONTH) + 1) + "/"
    + calendar.get(Calendar.DATE));
    String n = calendar.get(Calendar.YEAR) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE);
         System.out.print(n);
         return n;
    I have table name TEST
    ID DATE_IN
    1 942685200
    2 952448400
    When I write jsp I use method setDate in class TimeDate
    The result is
    ID DATE_IN
    1 1999/11/16
    2 2003/7/25
    Thanks you very much.

    It is unclear where you are having a problem.  Is your issue at runtime (when the form runs in the browser) or when working in the Builder on the form?
    Also be aware that you will need to sign your jar and include some new manifest entries.  Refer to the Java 7u51 documentation and blogs that discuss the changes.
    https://blogs.oracle.com/java-platform-group/entry/new_security_requirements_for_rias
    http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html

  • How to use unicode fonts in Oracle forms 10g?

    Hi I am working in forms 10g for quite a long time, the software that I have developed so far are all in English language. Now I have requirements to use Bengali Fonts in Forms 10g. I am facing difficulties doing that. Please reply with help. Thanks
    Hasan Al Mamun

    Check this forum post (though that is for 6i, it would be of helpful for you)
    How to use unicode fonts in Oracle forms 10g?
    -Arun

Maybe you are looking for

  • Free goods purchasing

    hi, when we create a PO for free goods indicator then the condition tab is not comming. so in that case if freight charge is with the free goods then how do we do that?same problem is comming for excise in case of creating MIRO for the free goods PO.

  • Error in generating COM DLL via DCOM Object Builder

    Hi, Iam creating a COM DLL for a BAPI and I always get the error when generating the DLL. I have Visual C++ 6.0 installed in the same PC.  Pls help.  Thanks. C:\vb>CALL "C:\Program Files\Microsoft Visual Studio\VC98\bin\vcvars32.bat" Setting environm

  • Automatic import mass data regional structure -  Program RSADRLSM01

    Hello, regarding the automatic import mass data to the regional structure via program RSADRLSM02, we are working in order to replace our third party provider. That is why, we need to deleted all the data imported from the city file and the references

  • Disabling of Deletion Button Indicator in COGI

    Hi Experts ,         We would like to disable the delete icon from COGI . This is to be done to prevent the users from deleting the error list. I had contacted the Basis team and they have maintained that this wasnt possible. Please suggest us a rang

  • FInal Cut X and 3rd Party Plugins from Previous Versions

    will they be compatible? i've got plenty of 3rd party plugins i've normally used with fcp 6. will i be able to use them with fcp x ? or is it a completely new platform? cheers.