Bobby Pan

Greenhorn
+ Follow
since Jul 12, 2002
Merit badge: grant badges
For More
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 Bobby Pan

I've made a class called Animal with the following constructor:

Animal(int id, String name, String kind)
Now I get data from a database and want to store this data in a Vector().
This goes like this:
Vector list = new Vector();
Statement st = connection.createStatement();
String query = "SELECT * FROM ANIMALS";
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
int id = rs.getInt("animalId");
String name = rs.getString("name");
String kind = rs.getString("kind");
Animal animal = new Animal(id, name, kind);
list.add(animal);
}
Now when I want to get the data from the Vector, and I print it on the screen, I get for every row in the Vector the same output. Something like this:
Fish blub Goldfish
Fish blub Goldfish
Fish blub Goldfish
etc.
Does somebody know how I can get this right??
21 years ago
Can someone help me with the following problem:
My code is:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=WebWinkel;username=gast;password=gast");
When I'm trying to connect to the database I get this error:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
What am I doing wrong??
Bob
21 years ago
JSP

Originally posted by Sean MacLean:
Looks like drivers are not in the server's classpath.
Sean


Thanks Sean, but how do I do that??
21 years ago
JSP
I've got this:
public class Logon extends HttpServlet {
private final static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private final static String url = "jdbc:microsoft:sqlserver://localhost:1433";
private final static String sql = "select * from USER where userId = 1";
private Connection connection = null;
private PreparedStatement statement = null;
private ServletContext context;
public void init(ServletConfig config) throws ServletException {
super.init(config);
context = config.getServletContext();
try {
Class.forName(driver);
connection = DriverManager.getConnection(url);
statement = connection.prepareStatement(sql);
}
catch (ClassNotFoundException e) {
System.err.println("Unable to load database driver");
throw new ServletException("Unable to load database driver");
}
catch (SQLException e) {
System.err.println("Unable to connect to database");
throw new ServletException("Unable to connect to database");
}
}
Now I get the following error
ERROR 500
Internal Servlet Error:javax.servlet.ServletException: Unable to load database driver
at store.Logon.init(Logon.java:27)
at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
at org.apache.tomcat.core.Handler.init(Handler.java:215)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:296)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.facade.RequestDispatcherImpl.doForward(RequestDispatcherImpl.java:222)
at org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:162)
at store.Controller.doGet(Controller.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
21 years ago
JSP