Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Connecting to SQL Server
Connecting to SQL Server [message #1385538] Mon, 09 June 2014 05:22
Kingsley Simon is currently offline Kingsley SimonFriend
Messages: 1
Registered: June 2014
Junior Member
I am trying to write a code that connects to my SQL database and selects data from it. using Java in Eclipse.

It seems not to be working and i dont know why. Can someone help? This code was written on an android application.

thanks
Kingsley

public void query2()
	{
	Log.i("Android" , "MySQL Connect Example.");
	Connection conn = null;
	try {
	String driver = "net.sourceforge.jtds.jdbc.Driver";
	Class.forName(driver).newInstance();
	//test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
	String connString = "jdbc:jtds:sqlserver://localhost:1433;instance=SQLEXPRESS;databaseName=EDMS;integratedSecurity=true";
	//String username = "xxxxxx";
	//String password = "xxxxxxxxxx";
	conn = DriverManager.getConnection(connString);
	Log.w("Connection", "open");
	Statement stmt = conn.createStatement();
	ResultSet reset = stmt.executeQuery("select * from Employee");
	 
	//Print the data to the console
	while(reset.next()){
		Log.w("Data: ", reset.getString(3));
//	              Log.w("Data",reset.getString(2));
	
	//setContentView(reset.toString());
	}
	conn.close();
	 
	} catch (Exception e)
	{
	Log.w("Error connection","" + e.getMessage());
	}
	}

Previous Topic:Problem importing a project
Next Topic:Java8 Nullness question: annotation is not applicable at this location
Goto Forum:
  


Current Time: Tue Dec 10 11:54:55 GMT 2024

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

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

Back to the top