JDBC *can* connect without specifying username and password
Posted in 2000
Hello I saw a posting here some days back asking if one could get away with not specifying the user name and password in the JDBC URL, since he wanted the user to log in as himself rather than with some canned URL. I just had a chance to try this out, and it appears that one can...heres the code I used if you are still around reading this newsgroup.... 1 import java.sql.*; 2 3 public class Test 4 { 5 public static void main (String[] argv) 6 { 7 try 8 { 9 Class.forName ("com.informix.jdbc.IfxDriver"); 10 } 11 catch (ClassNotFoundException cnfe) 12 { 13 System.out.println ("Class Not Found: " + 14 cnfe.getMessage ()); 15 } 16 String jdbc_url = "jdbc:informix-sqli://host:1234/dbname:" + 17 "informixserver=server_name"; 18 System.out.println (jdbc_url); 19 try 20 { 21 Connection conn = DriverManager.getConnection (jdbc_url); 22 PreparedStatement ps = conn.prepareStatement ( 23 "SELECT * FROM systables"); 24 ResultSet rs = ps.executeQuery (); 25 while (rs.next ()) 26 { 27 System.out.println (rs.getString (1)); 28 } 29 rs.close (); 30 ps.close (); 31 conn.close (); 32 } 33 catch (SQLException sqle) 34 { 35 System.out.println ("SQL Exception: " + 36 sqle.getMessage ()); 37 } 38 } 39 } This returns a list of tables as one would expect. Now if you wanted to log who was doing what, then you would probably need to wrap a call to getpwent () in a JNI call and use that. I have done that too, so if you want help mail me directly and I will send the code. HTH Sujit