Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Database connection chunk

mysql_select_db($database_conname, $conname);

$query_name = "SELECT * FROM tablename ORDER BY column DESC LIMIT 0, 10";
$name = mysql_query($query_name, $conname) or die(mysql_error());
$row_name = mysql_fetch_assoc($conname);
$totalrows_name = mysql_num_rows($conname);

Require once database connection

require_once('../include/filename.php');

Open a JDBC connection

This opens a JDBC connection givine a driver class name, database URL, user name and password. It is possible this method is deprecated and some newer procedure is preferred. I need to look into that.

    /*
    ** driverClass is the JDBC driver class name as a String.
    */

    try
    {
	Class.forName (driverClass);
	connection = DriverManager.getConnection (url,
	    userName, password);
	connection.setAutoCommit (false);
    }
    catch (SQLException ex)
    {
	/*
	** "Connect error"...
	*/
    }
    catch (java.lang.ClassNotFoundException ex)
    {
	/*
	** "Driver error"...
	*/
    }
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS