KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > sql > DriverManager

java.sql
Class DriverManager

java.lang.Object
  extended by java.sql.DriverManager
See Also:
Top Examples, Source Code, Driver, Connection

public static void deregisterDriver(Driver driver)
                             throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Connection getConnection(String url)
                                throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[266]Update a DB record
By Anonymous on 2003/05/29 14:25:36  Rate
//Declare a method and some variables and parameters. 
 public void UpdateStudentName ( String StFName, String StLName,String StNo )  throws SQLException  {  
  
  
 int RetValue; 
  
  
 // Initialize and load the JDBC-ODBC driver. 
 Class.forName  ( "jdbc.odbc.JdbcOdbcDriver" ) ; 
  
  
 // Make the connection object. 
 Connection Ex1Con = DriverManager.getConnection (  "jdbc:odbc:StudentDB;uid="admin";pw="sa" ) ; 
  
  
 // Create a simple Statement object. 
 Statement Ex1Stmt = Ex1Con.createStatement (  ) ; 
  
  
 //Make a SQL string, pass it to the DBMS, and execute the SQL statement 
 String SQLBuffer = "UPDATE Students SET FirstName = "+StFName+", LastName = "+StLName+" WHERE StudentNumber = "+StNo 
  
  
 RetValue = Ex1Stmt.executeUpdate (  SQLBuffer ) ; 
 System.out.println ( "Updated " + RetValue + " rows in the Database." ) ; 
  
  
  }  
  
  
 


[477]Open DB connection with username and password
By raqortega { at } hotmail { dot } com on 2005/09/21 13:50:38  Rate
connection = DriverManager.getConnection ( args [ 1 ] , "spectrum", "m0d3m" ) 

[504]_
By Anonymous on 2003/11/10 14:57:30  Rate
private Connection connectDatabase (  )   {  
 // load properties from jdbc.properties 
 Properties jdbcProps = new Properties (  ) ; 
 String driver = null; 
 String database = null; 
 String user = null; 
 String password = null; 
 Connection con = null; 
 try  {  
     jdbcProps.load ( Thread.currentThread (  ) .getContextClassLoader (  )  
            .getResourceAsStream ( "jdbc.properties" )  ) ; 
     database = jdbcProps.getProperty ( "database" ) ; 
     driver = jdbcProps.getProperty ( "driver" ) ; 
     user = jdbcProps.getProperty ( "user" ) ; 
     password = jdbcProps.getProperty ( "password" ) ; 
     if  (  database.equals ( "" )  || driver.equals ( "" )   )   {  
     System.out.println ( "No entry in jdbc.properties " 
                + "for driver or database URL found." ) ; 
     System.exit ( -1 ) ; 
      }  
     // register jdbc driver 
     Class.forName ( driver ) ; 
     con = DriverManager.getConnection ( database, user, password ) ; 
  }  catch  ( MissingResourceException mre )   {  
     System.out.println ( "Could not found jdbc.properties. " + mre ) ; 
     System.exit ( -1 ) ; 
  }  catch  ( IOException ioe )   {  
     System.out.println ( "Could not read jdbc.properties. " + ioe ) ; 
     System.exit ( -1 ) ; 
  }  catch  ( ClassNotFoundException cnfe )   {  
     System.out.println ( "Could not found the JDBC driver. " + cnfe ) ; 
     System.exit ( -1 ) ; 
  }  catch  ( SQLException sqle )   {  
     System.out.println ( "SQL-Exception occurs." + sqle ) ; 
     System.exit ( -1 ) ; 
  }  
 return con; 
  } 


public static Connection getConnection(String url,
                                       String user,
                                       String password)
                                throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Connection getConnection(String url,
                                       Properties info)
                                throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Driver getDriver(String url)
                        throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Enumeration<Driver> getDrivers()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int getLoginTimeout()
See Also:
setLoginTimeout(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public static PrintStream getLogStream()
See Also:
setLogStream(java.io.PrintStream)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static PrintWriter getLogWriter()
See Also:
setLogWriter(java.io.PrintWriter)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void println(String message)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void registerDriver(Driver driver)
                           throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setLoginTimeout(int seconds)
See Also:
getLoginTimeout()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public static void setLogStream(PrintStream out)
See Also:
getLogStream(), SecurityManager.checkPermission(java.security.Permission), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setLogWriter(PrintWriter out)
See Also:
getLogWriter(), SecurityManager.checkPermission(java.security.Permission), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags