+ Reply to Thread
Results 1 to 4 of 4

Thread: Connecting to a Database

  1. #1
    Learning Programmer reachpradeep is an unknown quantity at this point reachpradeep's Avatar
    Join Date
    Mar 2007
    Location
    India
    Posts
    41

    Connecting to a Database

    problem in connecting the database.. please reveiw my code and tell me there is any error.

    i used the JDBC-ODBC bridge to connect to a database

    try {
    Class.forName( "sun.jdbc. odbc.JdbcOdbcDri ver");
    String url = "jdbc : odbc:mydataba se";
    Connection con = DriverManager. getConnection( url, "login", "password");
    } catch (ClassNotFoundException e) {
    } catch (SQLException e) {
    }

  2. #2
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    do you have the drivers installed?
    is it throwing an exception? if so what is it?

    This is the code i use for a mysql connection:
    Code:
    package net.codecall.forums.general;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    
    public class MySqlConnect {
    
    	public static void main(String args[]) {
    		Connection con = null;
    		String dbname = "";
    		String dbuname = "";
    		String dbpassword = "";
    
    		try {
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			con = DriverManager.getConnection("jdbc:mysql:///" + dbname, dbuname, dbpassword);
    
    			if(!con.isClosed()){
    				System.out.println("Successfully connected to " + dbname);
    			}
    		} catch(Exception e) {
    			System.err.println("Exception: " + e.getMessage());
    		} finally {
    			try {
    				if(con != null){
    					con.close();
    				}
    			} catch(SQLException e) {}
    		}
    	}
    }

  3. #3
    Learning Programmer reachpradeep is an unknown quantity at this point reachpradeep's Avatar
    Join Date
    Mar 2007
    Location
    India
    Posts
    41
    i already used mysql connection.. i working good for me.
    but now i want to connect the database using JDBC-ODBC bridge.. previously i used same code. its works fine.. now its throwing an exception..

  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    what does the exception say?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Retrieving Access Database
    By tigger in forum Visual Basic Programming
    Replies: 0
    Last Post: 07-06-2007, 12:27 AM
  2. Best program for SQL database manipulation
    By Rhadamanthys in forum Database & Database Programming
    Replies: 3
    Last Post: 07-02-2007, 02:32 PM
  3. Best way to save lots of small values (in a database)?
    By Vantage in forum General Programming
    Replies: 2
    Last Post: 05-14-2007, 07:57 AM
  4. Database backup, with a twist.
    By Chrisms in forum Database & Database Programming
    Replies: 5
    Last Post: 09-05-2006, 01:17 PM
  5. Database and Database Users
    By DevilsCharm in forum Database & Database Programming
    Replies: 2
    Last Post: 08-27-2006, 10:22 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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