• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

urgent, please help!got problem of connecting to mysql database using JDBC

R

raybristol

Guest
hi, I got problem of connecting to mysql database using JDBC,I list what I did step by step and hoping you can tell me whether I did anything wrongly:

1. I have a jsp project called test4, I copy file 'mysql-connector-java-3.1.6-bin.jar' to folder 'test4\WEB-INF\lib'

2. export the whole project in war format: test4.war

3. upload it to live server

4. restart tomcat

at this point, I got ' java.lang.NullPointerException ' when try to connect the database.

5. I notice in the live server, in file 'tomcat4/conf/catalina.policy', I saw a example of granting the permission to a JDBC driver, so I adding the following in file 'catalina.policy':

grant codeBase "file:${catalina.home}/psa-webapps/test4/WEB-INF/lib/mysql-connector-java-3.1.6-bin.jar"{
permission java.net.SocketPermission "localhost:3306", "connect";
permission java.net.SocketPermission "127.0.0.1:3306", "connect";
};

but I still got the same exception 'java.lang.NullPointerException', I wonder if I did that wrong in policy file or anyother reason? I can't anything wrong in my code as it works perfectly in my machine, so it must be something else, I think the username and password should be correct.

Many thanks for your help!

In my development machine, I got no problem at all, in live server, the user name and password also right, as when I entering the live server login as root, I can do commmand 'mysql -urui -pchangeme Spottheballtv' with no problem, so I wonder how do I get more information to solve this problem?

exception 'java.lang.NullPointerException' doesn't give me too much helpful information for debugging, so I wonder what else Exception I need to catch in order to get more useful information?

Many thanks for your help again!

Ray

============================
my code is very simple:

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="payment.DbConnect" %>


<%
//out.println((DataSource)applicationEnv.lookup("jdbc/user"));
try{
java.sql.Connection con = null;
Statement stmt = null;
con=DbConnect.connectToDb("localhost", "Spottheballtv","rui","changeme");
stmt = con.createStatement();
//String query = "SELECT * FROM Ticket";
//ResultSet rs = stmt.executeQuery(query);
out.println("ok!");
}
catch (Exception ex)
{
out.println("1?!<br>");
out.println(ex);
ex.printStackTrace();
}
%>

my connection class:
package payment;

import java.sql.*;

public class DbConnect {
static String driverName = "com.mysql.jdbc.Driver";
static String dbUrl = "jdbc:mysql://";

public DbConnect() {
}


public static java.sql.Connection connectToDb(String hostName,String databaseName, String uid, String pw) throws Exception {
Connection conn = null;
String connName = dbUrl+hostName+":3306"+"/"+databaseName;
try{
Class.forName(driverName).newInstance();
conn = DriverManager.getConnection(connName+"?useUnicode=true&characterEncoding=GBK",uid,pw);
} catch (Exception e){ e.printStackTrace();}
return conn;
}
}
 
Does your /etc/my.cnf have "skip-networking" in the configuration file? JDBC doesn't leverage UNIX sockets, so it has to use TCP/IP. The default installation of MySQL is to NOT use the TCP/IP socket (3306).
 
Hi, thanks you so sooooooooooo much for your reply!!!!!!!!

I will check it soon and let you know how it goes, many many thanks again!!!!!!!
 
Back
Top