Information of total siteIndexHomeMaker

Site Map
Algorithms
Dutch
Fun
Medical
Music
Myself
Pictures
Problems
Programming
Search
NL:Index
Ziekten
Index of Java Programming
Getting Java Working
Java

Database Connections
Oracle
::
 
 
 
Java
Installation
Download Java from the java website from SUN
Configuration
 
 
Upstairs  Index  Contact
 
 
Connection to a database
Full ODBC compliant
    private void InitConnectionODBC() throws ConnectorException
	{
		String url = "jdbc:odbc:"+this.sDSN;
		try {
			Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
			if (loginUser.compareTo("")==0)
			{
				con = DriverManager.getConnection(url);
			}
			else con = DriverManager.getConnection(url,loginUser,loginPasswd);		
		}
		catch (java.lang.Exception ex){
			ex.printStackTrace();
			throw new ConnectorException();
		}
		try {
	    	 String sVendor = con.getMetaData().getDatabaseProductName();
	    	 if (sVendor.indexOf("Microsoft")>=0) this.iConLanguage=2;
	     }
	     catch (java.lang.Exception ex)
	     {
			ex.printStackTrace();
			throw new ConnectorException();
	     }
	}
    
MS-SQL server
Commented lines are from the previous classes used to connect with MS-SQL server
    private void InitConnectionSQLserver()  throws ConnectorException
	{
		try 
        {
			// Driver d = (Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
			// com.microsoft.jdbc.sqlserver.SQLServerDriver
			
            // user for SQLserver2000 driver Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// User for SQLserver2005 below
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//          DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
        }
     catch (ClassNotFoundException ex)
     {
     	ex.printStackTrace();
        throw new ConnectorException();
     }
     // String sConnect = "jdbc:sqlserver://192.168.30.43:1433;databaseName=Adventus";
     String sConnect = sDSN;
     try {
    	 // Example: jdbc:microsoft:sqlserver://localhost:1433
           con = DriverManager.getConnection(sConnect,loginUser,loginPasswd);
         }
     catch (java.lang.Exception ex){
			ex.printStackTrace();
			throw new ConnectorException();
     }
	}
    
PostGreSQL
    private void InitConnectionPostgres() throws ConnectorException
	{
		
        // String loginUrl = "jdbc:postgresql://192.168.30.130/aquaconf";
        // Load the PostgreSQL driver
        try 
           {
              Class.forName("org.postgresql.Driver");
           }
        catch (ClassNotFoundException ex)
        {
	       	ex.printStackTrace();
 			throw new ConnectorException();
        }
        try {
              con = DriverManager.getConnection(sDSN, loginUser, loginPasswd);
            }
        catch (java.lang.Exception ex){
			ex.printStackTrace();
			throw new ConnectorException();
        }
	}