CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Java

 problem with java-mysql connection

Print topic Send  topic

Author Message
albert85

Posts: 2
Posted: 12/26/2005, 8:49 PM

i have the problem of the connection java to MySQL
i oledi download the entire software:
-J2SE development kit 5.0 update6.0
-MySQL 4.1.16
-MySQL connector/j 3.1.12
is it enough for me to connect the java application to MySQL??
i oledi set the classpath like that:
my computer right click>properties >advanced >Environment Variables> System Variables>
create CLASSPATH and key in my .jar url which is:
C:\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
is it i inthe right path?
when i compile the source code, the error line come out:
Test.java:20: unreported exception java.lang.ClassNotFoundException; must be cau
ght or declared to be thrown
Class.forName ("JDBC_DRIVER");
^
1 error

And my source code is:::
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Test
{
static final String JDBC_DRIVER = "org.gjt.mm.mysql.driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/test";

public static void main( String args[] )
{
Connection connection = null;
Statement statement = null;

try
{
Class.forName ("JDBC_DRIVER");
connection =
DriverManager.getConnection(DATABASE_URL,"root"," ");
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
"SELECT name,last_name FROM t");
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.println( " Name is:");
for ( int i=1; i <= numberOfColumns;i++)
System.out.printf( "%-8s\t",metaData.getColumnName(i));
System.out.println();
while (resultSet.next())
{
for(int i=1;i <= numberOfColumns; i++)
System.out.printf("%-8s\t",resultSet.getObject(i));
System.out.println();
}
}
catch ( SQLException sqlException )
{
sqlException.printStackTrace();
System.exit(1);
}
finally
{
try
{
statement.close();
connection.close();
}
catch (Exception exception)
{
exception.printStackTrace();
System.exit(1);
}
}
}
}


What the problem of me? can someone who can solve this problem guide me to the right path
thank you..
View profile  Send private message
matheus

Posts: 386
Posted: 12/27/2005, 7:56 AM

It's Class.forName(JDBC_DRIVER) to get the variable value, note "JDBC_DRIVER" like a string.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.