new to this ... help needed please
Posted by: Samik Banerjee
Date: January 17, 2005 10:18AM

Hi,

I need to change something from ASP to JSP (connection to mySQL)

the ASP line is


DRIVER={MySQL ODBC 3.51 Driver};Server=***.***.*.**;Database=***;Uid=***;Pwd=***;

here is what I have done so far

<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>

<%!
// mysql driver
String driver = "MySQL ODBC 3.51 Driver";

// the "url" to our DB, the last part is the name of the DB
String url = "jdbc:mysql://***.***.*.**/***";

// the default DB username and password may be the same as your control panel login

String name = "***";
String pass = "***";

%>

<html>
<head>
<title>testServlet</title>
</head>
<body>
<p>Attempting to open JDBC connection to:... </p> <%=url%>
<%
try
{
// Test the DB connection by making an empty table
String tableStr = "CREATE TABLE test (testid mediumint(8), name varchar(100))";
Class.forName( driver );

// initialize the Connection, with our DB info ...
Connection con = DriverManager.getConnection( url, name, pass );

Statement stat = con.createStatement();
%>
<p> executing: <%=tableStr%></p>
<%
stat.executeUpdate( tableStr );
%>
<p> success.... </p>

<%
// close connection
con.close();
}

catch (SQLException sqle)
{ out.println("<p> Error opening JDBC, cause:</p> <b> " + sqle + "</b>"); }

catch(ClassNotFoundException cnfe)
{ out.println("<p> Error opening JDBC, cause:</p> <b>" + cnfe + "</b>"); }

%>
</body>
</html>

I think its the driver portion of the syntax which needs modification but am not sure hence the post.

thanx,
Sam

n.b: I replaced a few strings with "***" like IP / userid/pass etc.. :)

Options: ReplyQuote


Subject
Written By
Posted
new to this ... help needed please
January 17, 2005 10:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.