Listing 1. Example Java Code
import java.net.URL;
import exjava.sql.*;
import exgwe.sql.*;
public class jdbc_test {
public static void main (String argv[] )
{
try {
// Load the gweMysqlDriver JDBC Driver
Class.forName("exgwe.sql.gweMysqlDriver");
// Create the URL of the database we wish to
// connect to
String url = "jdbc:mysql://localhost:3306/test";
// Set up a connection
Connection con = DriverManager.getConnection(url,
"userid",
"pass");
// Create statement
Statement stmt = con.createStatement();
// Execute query
String query = "select name, phone from
test_table";
// Obtain the result set
ResultSet rs = stmt.executeQuery(query);
// Loop through each result row
while (rs.next() )
{ System.out.println( rs.getString(0),
rs.getInt(1) ); }
// Close result set
rs.close();
// Close statement"
stmt.close();"
// Close connection
con.close();
}
catch( Exception e ) { e.printStackTrace(); }
}
}
Copyright © 1994 - 2019 Linux Journal. All rights reserved.