Results 1 to 4 of 4

Thread: Problem while database connection in java

  1. #1
    Join Date
    Jan 2009
    Posts
    44

    Problem while database connection in java

    I am java user.I am trying the database connection in java , but unfortunately I am unsuccessful in it. I am getting lots of error while compilation.

    I used below code to make connection:
    Class.forName("sun.jdbc.odbc.JDBCODBCDriver");
    Connection con1 = DriverManager.getConnection("jdbc:odbc:dumy1"; "ab", "");
    Statement stmt = con1.createStatement();
    Can you determine what's wrong with this code? or Can you able to provide me the error-less code??...

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Problem while database connection in java

    The code which you have used in which it seems that there is incorrect connection string.

    Your code is :

    Class.forName("sun.jdbc.odbc.JDBCODBCDriver");
    Correct code should be:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Problem while database connection in java

    The following source of Java establish a JDBC connection to a mSQL database on a server "www.demomyserver.com'"

    // Establish a connection to a mSQL database using JDBC.
    import java.sql.*;

    class JdbcTest1 {

    public static void main (String[] args) {
    try
    {
    // Step 1: Load the JDBC driver.
    Class.forName("com.imaginary.sql.msql.MsqlDriver");
    // Step 2: Establish the connection to the database.
    String url = "jdbc:msql://www.demoserver.com:1114/contact_mgr";
    Connection conn = DriverManager.getConnection(url,"user1","password");
    }
    catch (Exception e)
    {
    System.err.println("Got an exception! ");
    System.err.println(e.getMessage());
    }
    }
    }
    I hope this program will help you to understand JDBC connection..

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Problem while database connection in java

    While making database connection in java please make sure that you are following the below steps:

    1. Loading the Driver> 2. Making the Connection> 3. Using the DriverManager Class> 4. Using a DataSource Object for a connection.

    For detail information visit the below link:

    http://java.sun.com/docs/books/tutor...onnecting.html
    Last edited by MindSpace; 17-11-2009 at 11:34 AM.

Similar Threads

  1. How a Java program can be connected through database ?
    By Chellam in forum Software Development
    Replies: 4
    Last Post: 09-12-2010, 08:41 AM
  2. Database generator for java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 01:56 PM
  3. Java in oracle 9i database
    By Gerri in forum Software Development
    Replies: 4
    Last Post: 03-02-2010, 08:35 PM
  4. Connection of Java applications to Database
    By Gerri in forum Software Development
    Replies: 3
    Last Post: 27-01-2010, 02:58 PM
  5. Java and database
    By AMISH in forum Software Development
    Replies: 5
    Last Post: 12-12-2009, 07:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,624,057.71083 seconds with 17 queries