This week's book giveaway is in the Android forum.
We're giving away four copies of Android Programming: The Big Nerd Ranch Guide and have Bill Phillips & Chris Stewart on-line!
See this thread for details.
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDBC using MSQL works  RSS feed

 
Kevin Cary
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
}
}
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!