JDBC Informix connect
Posted in 2007
Topics: Connectivity: ODBC / JDBC / .NET, Security, Permissions & Auditing
Hi, I am trying to connect to an Informix database through my JDBC application, but it simply hangs. The DriverManager.getConnection() method never returns. I tried and tested the db connection using ODBC and it works. I made sure all the jar files are in my classpath. I used exactly the same parameters as I used in my ODBC testing. Here is my program: public class Test { public static void main(String[] args) throws Exception { Class.forName("com.informix.jdbc.IfxDriver"); String url = "jdbc:informix-sqli:// 192.168.0.5:5000:informixserver=srikanth_ifx"; Connection connection = DriverManager.getConnection(url, "srikanth", "srikanth"); // This line hangs connection.setAutoCommit(false); connection.close(); } } I tried with the following Jdbc URL also:- "jdbc:informix-sqli:// 192.168.0.5:5000:informixserver=srikanth_ifx:username=srikanth;password=srikanth"; But still they don't work. I also tried JDBC-ODBC connection, in that case I get a SQLException and it just says "General Error" Any help is thankfully appreciated! -- Srikanth
Srikanth wrote: > Hi, > > I am trying to connect to an Informix database through my JDBC > application, but it simply hangs. The DriverManager.getConnection() > method never returns. > > I tried and tested the db connection using ODBC and it works. > > I made sure all the jar files are in my classpath. I used exactly the > same parameters as I used in my ODBC testing. > > Here is my program: > > public class Test { > public static void main(String[] args) throws Exception { > Class.forName("com.informix.jdbc.IfxDriver"); > > String url = > "jdbc:informix-sqli:// > 192.168.0.5:5000:informixserver=srikanth_ifx"; > Connection connection = > DriverManager.getConnection(url, "srikanth", "srikanth"); // > This line hangs > > connection.setAutoCommit(false); > connection.close(); > } > } > > > I tried with the following Jdbc URL also:- > "jdbc:informix-sqli:// > 192.168.0.5:5000:informixserver=srikanth_ifx:username=srikanth;password=srikanth"; > > But still they don't work. > > I also tried JDBC-ODBC connection, in that case I get a SQLException > and it just says "General Error" > > Any help is thankfully appreciated! > > -- Srikanth > Just two things, don't know if it will help: 1. you did not specify a database name within the URL jdbc:informix-sqli://192.168.0.5:5000/<DBNAME>:... 2. the delimiter for the options (informixserver, username, ...) is a ';' not ':'.
I believe you need to register your driver, not just load the class. I always use this connection code (which also prints errors): Connection con; static createConnection(String url) { try { String ifxDriver = "com.informix.jdbc.IfxDriver"; // Register the INFORMIX-JDBC driver Driver IfmxDrv = (Driver) Class.forName(ifxDriver).newInstance(); Properties pr = new Properties(); // add whatever relevant properties you need con = DriverManager.getConnection(url, pr); } catch (SQLException e) { sqlerr(e); } catch (Exception e) { System.err.println("FAILED: Could not load Informix JDBC driver"); System.exit(1); } } static void sqlerr(SQLException e) { System.err.println("SQL ERROR "+ ((SQLException)e).getErrorCode()+": "+e.getMessage()); SQLException e1 = ((SQLException)e).getNextException(); if (e1 != null) System.err.println(e1.getMessage() +" ("+e1.getErrorCode()+")"); System.exit(1); } hope this helps, Zachi On Apr 26, 10:56 am, Srikanth <sri1...@gmail.com> wrote: > Hi, > > I am trying to connect to an Informix database through my JDBC > application, but it simply hangs. The DriverManager.getConnection() > method never returns. > > I tried and tested the db connection using ODBC and it works. > > I made sure all the jar files are in my classpath. I used exactly the > same parameters as I used in my ODBC testing. > > Here is my program: > > public class Test { > public static void main(String[] args) throws Exception { > Class.forName("com.informix.jdbc.IfxDriver"); > > String url = > "jdbc:informix-sqli:// > 192.168.0.5:5000:informixserver=srikanth_ifx"; > Connection connection = > DriverManager.getConnection(url, "srikanth", "srikanth"); // > This line hangs > > connection.setAutoCommit(false); > connection.close(); > } > > } > > I tried with the following Jdbc URL also:- > "jdbc:informix-sqli:// > 192.168.0.5:5000:informixserver=srikanth_ifx:username=srikanth;password=srikanth"; > > But still they don't work. > > I also tried JDBC-ODBC connection, in that case I get a SQLException > and it just says "General Error" > > Any help is thankfully appreciated! > > -- Srikanth