Closed Thread
Results 1 to 4 of 4

Thread: Connecting to a Database

  1. #1
    reachpradeep's Avatar
    reachpradeep is offline Learning Programmer
    Join Date
    Mar 2007
    Location
    India
    Posts
    41
    Rep Power
    0

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    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) {}
    		}
    	}
    }

  4. #3
    reachpradeep's Avatar
    reachpradeep is offline Learning Programmer
    Join Date
    Mar 2007
    Location
    India
    Posts
    41
    Rep Power
    0
    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..

  5. #4
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    what does the exception say?

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Beginner Connecting to MYSQL Database!
    By Epatron in forum PHP Tutorials
    Replies: 7
    Last Post: 08-16-2011, 11:14 AM
  2. Connecting a database with an application
    By sebkom in forum C# Programming
    Replies: 5
    Last Post: 03-13-2010, 03:32 AM
  3. Connecting to MySQL database
    By Vswe in forum Database & Database Programming
    Replies: 4
    Last Post: 08-25-2009, 02:34 PM
  4. Need Help Connecting to a Database for Logins - VB6
    By Respected-SpyderZ in forum Visual Basic Programming
    Replies: 2
    Last Post: 07-30-2008, 03:11 AM

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