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) {
}
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) {} } } }
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..
what does the exception say?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks