The Artima Developer Community
Sponsored Link

Java Answers Forum
MySQL Help!

1 reply on 1 page. Most recent reply: Nov 10, 2002 10:11 PM by twisty

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ClickB

Posts: 1
Nickname: clickb
Registered: Nov, 2002

MySQL Help! Posted: Nov 10, 2002 9:22 AM
Reply to this message Reply
Advertisement
I have this class:

package db;
import java.sql.*;
 
public class DbAccess
{
String url= "jdbc:mysql://localhost/agenda?";
String user = "root";
String pass = "";
Connection conn = null;
 
public void DbAccess(){
try{		
Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
System.out.println("Loadin driver");
conn = DriverManager.getConnection(url, user, pass);
System.out.println("Making connection");
}catch(Exception E){
System.err.println("Unable to load driver and make connection.");
E.printStackTrace();
}
}
 
public ResultSet execQuery(String query){
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
}catch (Exception E) {
System.err.println("Execute query");
E.printStackTrace();
}
return rs;
}
}


and this jsp page which call the class DbAccess:

<%@ page import = "java.sql.*"%>
 
<%
try{		
agenda.DbAccess dbprueba = new agenda.DbAccess();
ResultSet dbrs = dbprueba.execQuery("Select * from tbllogin");
while (dbrs.next()){
out.println(dbrs.getString("username") + "  " + dbrs.getString("password"));
}
}catch(Exception E){
System.err.println("Unable to load driver and make connection.");
E.printStackTrace();
}
%>


I also have the mm.mysql-2.0.4-bin.jar in the classpath, but when I call the jsp page the tomcat console return me the error: java.lang.NullPointerException
What is wrong??? Can somebody help me???


twisty

Posts: 22
Nickname: twisty
Registered: Nov, 2002

Re: MySQL Help! Posted: Nov 10, 2002 10:11 PM
Reply to this message Reply
Could you please post the full error message?

Flat View: This topic has 1 reply on 1 page
Topic: searching a character from a string Previous Topic   Next Topic Topic: Help Finding Slideshow Applet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use