Eclipse (jdbc) and mysql database [message #896401] |
Wed, 18 July 2012 05:57  |
Eclipse User |
|
|
|
Hello everyone
Started using eclipse and tried connecting to a local mysql database.
Used buildpath and added a new external source (the .jar) and created on my pc a classpath to the .jar file too.
The problem i have is, i dont get a error, so i cant figure out what im doing wrong. As far as i can tell its stuck on the "DriverManager.getConnection" line.
Could someone help me and tell me what im doing wrong?
Thanks
import java.sql.*;
public class DbConnection {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8080/test","root","password");
PreparedStatement statement = con.prepareStatement("select * from teststuff");
ResultSet result = statement.executeQuery();
while(result.next()) {
System.out.println(result.getInt(1)+" "+result.getString(2));
}
result.close();
statement.close();
con.close();
} catch(Exception ex) {
System.out.println("****** EXCEPTION ****** -->" +ex);
}
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09532 seconds