Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!

Michael McAuliffe

Greenhorn
+ Follow
since Aug 22, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael McAuliffe

Is this a good book to have for a beginner in Eclipse. I have tutorials on Eclipse, but confused by the plug-ins. MyEclipse, IceFaces, Spring, etc.
Thank you for the help. As a newbie, that is learning OTJ it is a huge learning curve.
Yes, the table is a working table, used to validate the information. It than updates other tables using database APIs.
Sorry! I thought the problem was in the DBHandler class. Here is the code

Being a newbie to Java coding, I'm stump on what is causing this problem. I execute a query and able to process 1 record from the result set. When it attempts to get 2nd record, it state that the result set is closed.

What did I do incorrect?

Calling code

DBHandler dbHandler = DBHandler.getInstance();
dbHandler.connect();

SQL = "Select * from chq_resources where interfacedate is null";
rs = dbHandler.executeQuery(SQL);

// Process the rows
while (rs.next()) {

Database connection code

import java.sql.*;


public class DBHandler {
// the instance
private static DBHandler dbHandler = new DBHandler();
// Declare the JDBC objects
Connection con = null;
Statement s = null;
ResultSet resultset = null;
// private so no one can access it externally
DBHandler() {

}

public static DBHandler getInstance() {
return dbHandler;
}

// connect to DB
public void connect() {
try {
String connectionUrl =
"jdbc:sqlserver://dtw-xxxxxx:1433;databaseName=xxxxxxx;" +
"user=xxxxx;password=xxxxx";

// Establish the connection
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);

s = con.createStatement();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet executeQuery(String query) {
try {
resultset = s.executeQuery(query);
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resultset;

}
public void executeUpdate(String query) {
try {
s.executeUpdate(query);
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public void disconnect() {
// Close the connection
try {
s.close();
con.close();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
Whichever is easier to call for a beginner. I don't know XML. The current version of the program is using the database APIs, but it is written in a subset of vbscript, that is used by SQL Server.

Is it easier to use the database or web apis? Or is the coding the same?

I'm new to Java, WSDL, XML.
10 years ago
I hope that I'm able to explain.

I'm writing a program that needs to update a SQL Server database. The program reads in a CSV file, write it to a SQL Server table. It then retrieves the rows from the table and edits the data. The next step is to retrieve the rows that are not in error and update the SQL Server tables with the data. To perform the update, it needs to execute APIs. The APIs are installed on both the database server and web server. They are the same.

The software package that was purchase has the same APIs executing on the database server and the web server.

I had asked some people that I know are more knowledgeable than I am and they suggested using WSDL.

Is there another way of calling an APIs other that using WSDL?
10 years ago
Sorry, it took so long to reply.

Thank you for the help. It is working.
I'm converting a SQL Server Data Transformation Service (DTS) package to a Java program.

It required to call multiple database APIs (there are also web APIs) to update the database. The APIs are from a purchase vendor package.

What is the best way of doing this? It has been suggested that I use WSDL.

I'm new to Java and have read some on WSDL.
10 years ago
Thanks to everyone that has offered assistance.

I tried the following, but receiving errors.

1. private static Connection connection;

"The field connection cannot be declared static; static fields can only be declared in static or top level types"

2. Statement s = DBHandler.getConnection.createStatement();
"Cannot make a static reference to the non-static method getConnection() from the type CHRISInterface.DBHandler"

I changed the class to static and the getConnection method to static

Is there a reason why this had to be done?

[B}public static class DBHandler { [/B]
// The Instance
private static Connection connection;

//Private so one can access it externally
private DBHandler() {
}

// Connect to DB
public static Connection getConnection() {
try {
if (connection == null) {
// Create a variable for the connection string
String connectionUrl =
"jdbc:sqlserver://testServer:1433;databaseName=test;" +
"user=testuser;password=testpass";
// Declare the JDBC objects
// Establish the conenction
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection = DriverManager.getConnection(connectionUrl);
}
} // end try
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
}
Being new to Java and learning JDBC.

I was informed that each connection to the database has a large overhead and that it is better to make only 1 connection and reuse.

I'm not the DBA, not able to configure SQL Server
Jon

Thank you for the reply, it was very helpful

Just another question.

public static void main(String[] args) {
try {

DBHandler dbHandler = new DBHandler.getInstance();
dbHandler.connect();

CHRISInterface.LoadFile();
CHRISInterface.validateData();
dbHandler.disconnect();

}

Using the code in main, would I pass the dbHandler to the LoadFile and validateData classes? This is where the SQL is located.
I'm new to Java and this is my first program.

I have coded a 2 private classes that use the Sql Server database in each class.

Is it possible to code a separate class (databaseConenction) that issue the connection and it is usable in the other classes?

Code:

// Create a variable for the connection string
String connectionUrl ="jdbc:sqlserver://xxxxxxxxx.xxxx.xxxx.xxxx:1433;databaseName=name;user=user;password=pass";
// Declare the JDBC objects
Connection con = null;
// Establish the connection
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
In Chapter 6 on page 138 - 139, the SimpleDotCom module is modified and renamed DotCom. The modification to the Game.java module are not included.

What changes to the Game.java module must be made to get it to work?
10 years ago