[plug] Database advice - Newbie
James Devenish
devenish at guild.uwa.edu.au
Tue Jun 24 12:47:08 WST 2003
In message <1056427179.18164.10.camel at latte.internal.itmaze.com.au>
on Tue, Jun 24, 2003 at 11:59:39AM +0800, Onno Benschop wrote:
> I especially don't like constructing SQL text queries with PHP (is
> there another way?).
> I' not sure what you're asking here,
Specifically, how to construct SQL queries (esp. UPDATEs) without having
code that is like "UPDATE blah WHERE ".stuff." blah $stuff"
> A simple Hello World in PHP would look like this:
[...]
> Given this, what does it look like in JDBC?
(There's probably nothing that can go wrong with a minimal Hello World
programme, especially when it sidestep matters such as modifying a
database, managing connections, and handling errors, so I don't know
what purpose this serves. But the question was asked...)
Connection c = SQLBroker.getConnection( "mysql_url", "mysql_user", "mysql_password", "my_database" );
ResultSet r = c.getStatement().executeQuery( "SELECT * FROM my_table" );
while ( r.next() ) {
for ( int i = 1; i <= r.getMetaData().getColumnCount(); i++ ) {
if ( i > 1 )
System.out.print( "\t" );
System.out.print( r.getString( i ) );
}
System.out.println();
}
More information about the plug
mailing list