permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes JDBC using MSQL works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC using MSQL works" Watch "JDBC using MSQL works" New topic
Author

JDBC using MSQL works

Kevin Cary
Ranch Hand

Joined: Jan 24, 2001
Posts: 53
In the beginning, I was modifying the classpath in the autoexec.bat file thinking this would search for the MsqlDriver. This hasn't worked. Secondly I was using WinZip to open the jar file which seems to be a mistake. What has worked is to use the jar utility to open the jar file and to copy the driver to the directory indicated by the package and then importing this package into you application. The code below was shamelessly ripped off and does work. There may be other solutions but this one has worked for me.
import java.sql.*;
import com.imaginary.sql.msql.*;

public class Connect
{
public static void main ( String args[] )
{
Connection mSQL = null;
try
{
new MsqlDriver();
String url = "jdbc:msql:///StockMarket";
Connection mSQLcon = DriverManager.getConnection ( url );
Statement stmt = mSQLcon.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM Stock");
while( rs.next())
{
System.out.println( rs.getString(1));
}
}
catch ( SQLException sql )
{
sql.printStackTrace();
}
finally
{
if ( mSQL != null )
{
try
{
mSQL.close();
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
}
}
}
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: JDBC using MSQL works
 
It's not a secret anymore!