Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse (jdbc) and mysql database(Cant connect)
Eclipse (jdbc) and mysql database [message #896401] Wed, 18 July 2012 09:57 Go to next message
Eru Iluva is currently offline Eru IluvaFriend
Messages: 2
Registered: July 2012
Junior Member
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);
		}
	}

}




Re: Eclipse (jdbc) and mysql database [message #896411 is a reply to message #896401] Wed, 18 July 2012 10:31 Go to previous messageGo to next message
Shyam Prakash is currently offline Shyam PrakashFriend
Messages: 11
Registered: June 2012
Junior Member
Mysql db default port number is 3306 and 8080 is default http port. Try changing the port.

~Shyam
Re: Eclipse (jdbc) and mysql database [message #896415 is a reply to message #896411] Wed, 18 July 2012 10:40 Go to previous messageGo to next message
Eru Iluva is currently offline Eru IluvaFriend
Messages: 2
Registered: July 2012
Junior Member
I could hit myself, so stupid. Yea didnt notice that.

Thanks, fixed.
Re: Eclipse (jdbc) and mysql database [message #897093 is a reply to message #896415] Sat, 21 July 2012 16:45 Go to previous message
Javin Paul is currently offline Javin PaulFriend
Messages: 48
Registered: July 2011
Location: mumbai
Member

Though issue is fixed, I feel strange why your Java code doesn't throw Exception like normally in case of port clash it throw "java.net.BindException:address already in use" etc ??
Previous Topic:Can't install plugins in Juno
Next Topic:Eclipse installation on centos 6 server
Goto Forum:
  


Current Time: Fri Dec 19 06:49:10 GMT 2014

Powered by FUDForum. Page generated in 0.02566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software