• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

JSP to MS Access 2K and mysql connection String ?

kmthien

Senior member
Hi,

I got the following JSP code :

<sql:setDataSource var="mydb" scope="application"
driver="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc😱dbc:mydb"
user="abc"
password="123"
/>

The above is DSN connection. How to change it to DSN-less and connect with MS Access and MySql ? Pls help...

kmthien
 
First, to hookup with MS Acces you do the same basic thing. Create a DSN for the MS Access DB your trying to access and then use
the appropriate drive for MS Access. IE: not the sun.jdbc.....

Second, here is some servlet code that gets a connection for MySQL:

import java.sql.*;
/**
* This is an example of how to create a connection using MySql JDBC
* drivers.
*/
public class MySQLCon
{
/* Declare private variables */
private Connection con;
private Driver MySQLDriver;
/*
Connection object for MySQL.
MySQLCon.GetCon returns a connection object to be used for preparing SQL statements, etc.
MySQLCon.SetCon creates an initial connection. Called automatically if GetCon is called before a connection is set
*/
public MySQLCon() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
}
public synchronized Connection getCon() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
if (con == null)
setCon();
return con;
}
public synchronized void setCon() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
/* Set up JDBC */
if (con != null)
return;{t
MySQLDriver = (Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance(); ext2}
/*Connect to DB
Replace databasename with the name of your database
Replace myusername with your username
Replace mypassword with your password */
con = DriverManager.getConnection("jdbc:mysql://mysql.kgbinternet.com/databasename?user=yourusername&password=yourpassword");
/* Done connecting to DB */;
}
public synchronized void setCon(Connection connect) throws SQLException,ClassNotFoundException,IllegalAccessException,InstantiationException
{
con=connect;
}
}
 
Back
Top