Page 1 of 2 12 LastLast
Results 1 to 20 of 26
  1. #1
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Database Connaction in Java

    Hi,

    I'm using oracle 10g Database and Java 'jdk1.7.0_45' version.I have to a create program to insert data into a table.
    Could you please let me know how to do it.
    Thanks and Regards,
    Faziludeen

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connaction in Java

    Strange question. The answer is: you use the incredible amount of information available to you to learn how to do SQL from Java.

    I'll save you 5 seconds of Googling: You learn "JDBC".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi,

    Sorry.I'm new in Java.

    I got an error while runing below code.could you please help me for resolving it.

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Properties;

    /**
    * Simple Java Program to connect Oracle database by using Oracle JDBC thin driver
    * Make sure you have Oracle JDBC thin driver in your classpath before running this program
    * @author
    */
    public class OracleJdbcExample {

    public static void main(String args[]) throws SQLException {
    //URL of Oracle database server
    String url = "jdbc:oracle:thin:@localhost:1632:DEVROOT32";

    //properties for creating connection to Oracle database
    Properties props = new Properties();
    props.setProperty("user", "scott");
    props.setProperty("password", "tiger");

    //creating connection to Oracle database using JDBC
    Connection conn = DriverManager.getConnection(url,props);

    String sql ="select sysdate as current_day from dual";

    //creating PreparedStatement object to execute query
    PreparedStatement preStatement = conn.prepareStatement(sql);

    ResultSet result = preStatement.executeQuery();

    while(result.next()){
    System.out.println("Current Date from Oracle : " + result.getString("current_day"));
    }
    System.out.println("done");

    }
    }





    ======================

    --------------------Configuration: OracleJdbcExample - JDK version 1.7.0_45 <Default> - <Default>--------------------
    Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1632:DEVROOT32
    at java.sql.DriverManager.getConnection(DriverManager .java:596)
    at java.sql.DriverManager.getConnection(DriverManager .java:187)
    at OracleJdbcExample.main(OracleJdbcExample.java:25)

    Process completed.

    -----------------------------------------------
    Database TNS :-

    UST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ust)
    )
    )

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Database Connaction in Java

    That error says you don't have the driver jar file on the classpath at runtime.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connaction in Java

    Something that you would have easily found out if you copy pasted java.sql.SQLException: No suitable driver found for jdbc:oracle:thin into Google - luckily for you there have been thousands of people who ran into this before you did.

    Notice what I did there: I stripped that part out of the error which is specific to you (host name, port number, database name).
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi,

    which driver jar file need to install?.Could you please give me link for dowloading it

    Thanks and Regards,
    Faziludeen

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connaction in Java

    You download the Oracle JDBC driver which you can find on the Oracle.com download site.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Database Connaction in Java

    I would've guessed that the jdbc stuff came with the database installation.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connaction in Java

    That would be a bit of a poor decision as then you've most likely got an out-of-date driver version.

    EDIT: note that you are probably right and there is likely a driver bundled with the database installation. But then it is still worth it to look for a more up to date one on the download site. Its free, after all.
    Last edited by gimbal2; 10-27-2014 at 01:55 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Database Connaction in Java

    Quote Originally Posted by gimbal2 View Post
    That would be a bit of a poor decision as then you've most likely got an out-of-date driver version.

    EDIT: note that you are probably right and there is likely a driver bundled with the database installation. But then it is still worth it to look for a more up to date one on the download site. Its free, after all.
    My guess would also be that there's a reference to the latest version of that jdbc stuff, bundled with the database installation.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  11. #11
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi,
    I have downloaded JDBC driver 'ojdbc14.jar' from oracle site.How to install it.Just copy to the following folder or else?

    'C:\Program Files\Java\jdk1.7.0_45\bin'

    Thanks and Regards,
    Faziludeen

  12. #12
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi All,

    Could you please clarify my above mentioned doubts.

    Thanks in advance.

    Regrds,
    Faziludeen

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Database Connaction in Java

    You stick it wherever your other runtime jar files are for your project, usually a lib directory in your project.
    Add it to the runtime classpath.

    Do not stick it in with the Java deployment.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connaction in Java

    Quote Originally Posted by fazilabu@gmail.com View Post
    Hi,
    I have downloaded JDBC driver 'ojdbc14.jar' from oracle site.
    Why? Are you using Java 1.4?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi,

    Current I have 'ojdbc14.jar' .Could you please let me know which JDBC Driver version have to download for 'jdk1.7.0_45'.Is JDBC Driver have to copy for the following folder or else?
    C:\Program Files\Java\jdk1.7.0_45\lib

    Thanks and Regards,
    Faziludeen

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Database Connaction in Java

    I said above, you do not want to be copying project jar files into your JDK or JRE deployment.
    You put them in a lib directory in your project.

    As for which driver, find your version of Oracle here and then find a driver that fits your Java version.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi All,

    Still I got the following exception.Could you please help me to resolve it.

    --------------------Configuration: OracleJdbcExample - JDK version 1.7.0_45 <Default> - <Default>--------------------
    Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:fazil
    at java.sql.DriverManager.getConnection(DriverManager .java:596)
    at java.sql.DriverManager.getConnection(DriverManager .java:187)
    at OracleJdbcExample.main(OracleJdbcExample.java:25)

    Process completed.




    Please check the following classPath

    CLASSPATH :-

    C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar

    Thanks and Regards,
    Faziludeen

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Database Connaction in Java

    And where is that classpath defined?
    How are you running this?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    Join Date
    Oct 2014
    Posts
    10
    Rep Power
    0

    Default Re: Database Connaction in Java

    Hi,

    Classpath is defined in the following path:-

    Control Panel --> Advanced Tab-->Environment Variables-->User variables for itec-->
    Variable Name:- CLASSPATH
    vARIABLE vALUE :- C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar

    Running through 'JCreator'.

    Thanks and Regards,
    Faziludeen

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Database Connaction in Java

    Don't define the CLASSPATH there.
    Remove that one.
    If you execute a jar file, run in an IDE, or run in a webserver that value is not used.

    You need to find out how to define the runtime classpath in your IDE.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2014, 02:50 PM
  2. Java Swing application + Database on server (Java EE?)
    By twist900 in forum Advanced Java
    Replies: 5
    Last Post: 12-20-2013, 02:04 PM
  3. Create registration form | insert into database | call the database
    By FamilyGuy in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-23-2012, 11:08 AM
  4. Java database
    By walkees in forum Java Software
    Replies: 0
    Last Post: 12-13-2011, 06:32 PM
  5. help with database using java
    By computerbum in forum New To Java
    Replies: 5
    Last Post: 04-26-2010, 01:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •