Re: [PHP] Re: How to connect to mysql through JAVA?

2002-04-24 Thread Richard Fox

The last post is using the MySQL JDBC from a Java Server Page in a servlet
environment. I never tried to run this from Java imbedded in a PHP script.
You would have to remove the exception handling, at least.

I dispatch a Java Server Page from my php script (write to a socket), do
some java stuff there involving my MySQL db, and return the output to my php
script (read from socket).

I can send more details on this if you're interested.

Rich



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: How to connect to mysql through JAVA?

2002-04-24 Thread Richard Fox


Sourceforge MySQL JDBC driver
http://mmmysql.sourceforge.net/

maybe this code frag will be helpful...

  String connectionURL = "jdbc:mysql://centauri.sbs:3306/dbname";
  Connection conn = null;
  Statement statement = null;
  ResultSet rset = null;
  try {
 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
 conn = DriverManager.getConnection(connectionURL,"servlet","password");
 statement = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
 rset = statement.executeQuery(
"SELECT * FROM BROWSER WHERE sessionID='"
 + request.getParameter("session_id") +"'");

 .. now use rset
  } // try
  catch( ClassNotFoundException e ) {
 PrintWriter pw = new PrintWriter(out, true);
 pw.println("Couldn't find the mm database driver: "
 + e.getMessage());
 }
  catch( InstantiationException e ) {
 PrintWriter pw = new PrintWriter(out, true);
 pw.println(e.getMessage());
 }
  catch( IllegalAccessException e ) {
 PrintWriter pw = new PrintWriter(out, true);
 pw.println(e.getMessage());
 }
  catch( SQLException e ) {
 PrintWriter pw = new PrintWriter(out, true);
 pw.println("SQL Problem: " + e.getMessage());
 pw.println("SQL State: " + e.getSQLState());
 pw.println("Vendor Error: " + e.getErrorCode());
 }
  finally {
try {
  if ( conn != null )
  conn.close();
  }
catch( SQLException e ) {
  PrintWriter pw = new PrintWriter(out, true);
  pw.println(e.getMessage());
  }
}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php