Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with JDBC

Status
Not open for further replies.

cal555

Programmer
May 5, 2006
71
0
0
US
Hi,
I am learning java for my job, and they are starting to show me JDBC and we use SQL Server for a database. So I am trying to get a simple progam to work.ich retuns the customers addres form the database; but it is geting stuck on the line DriverManager.getConnection and the line stmt.ExecuteQuery(sqlCmdString);

can someone tell me what I am doing wrong.
Thank you

import java.sql.*;

class Sqlmain {

public static void main(String args[])
{

Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");

String url = "jdbc:microsoft:sqlserver://:1433";

Connection con = DriverManager.getConnection(url, "Customers");

con.setCatalog("northWind");

Statement stmt = con.createStatement();

String sqlCmdString = "select * from Customers";

ResultSet rs = stmt.ExecuteQuery(sqlCmdString);

while (rs.next())
{
rs.getString(("address").trim());
}

}
}
 
Yes, it is the get connection and as I said in the question, it is also stmt.ExecuteQuery(sqlCmdString). Theses are on lines 12 and 20. in the information that the company gave me and a book that I have this should be all I need, but it must be missing something.
 
Well.
You look at the api-docs.
Since there is only one import, you only need to browse java.lang and java.sql to find DriverManager.

Guess where you'll find the class?

Then you look for a method 'getConnection' and compare your parameters to the parameters, documented.

Repeat procedure for Statement.

don't visit my homepage:
 
It would help if you posted the actual compilation errors, and the runtime stack trace.

But certainly, getConnection() takes a url string, a username and a password.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top