java中MySQL与驱动jdbc连接不上,想请教高手:jdbc驱动:mysql-connector-java-5.1.29-bin.jar怎么用啊?

packagenet.chat;importjava.sql.*;importjava.lang.ClassNotFoundException;publicclassBa... package net.chat;
import java.sql.*;
import java.lang.ClassNotFoundException;
public class BaseConn {
private Connection conn = null;
private Statement stmt = null;
private PreparedStatement ps = null;
private ResultSet rs = null;
public BaseConn() throws SQLException,ClassNotFoundException{
try
{
String driverName ="com.mysql.jdbc.Driver";
String userName = "root";
String passWord = "123";
String url="jdbc:mysql://localhost:3306/ChatRoom";
Class.forName(driverName);
Connection conn = DriverManager.getConnection(url,userName,passWord);
return ;
}
catch(SQLException e)
{
System.out.println("Error occured when Connect DataBase:"+e);
throw e;
}
catch(ClassNotFoundException e)
{
System.out.println("Error occured when Connect DataBase:"+e);
throw e;
}
}
public PreparedStatement preparedStatement(String sql) throws SQLException
{
try
{
ps = conn.prepareStatement(sql);
return ps;
}catch(SQLException e)
{
System.out.println("Error occured when create preparedStatement:"+e);
throw e;
}
}
public ResultSet executeQuery(String sql) throws SQLException
{
rs = null;
try {
rs = stmt.executeQuery(sql);
}
catch (SQLException ex) {
System.out.println("Error occured when query database:" + ex);
throw ex;
}
return rs;
}
public int executeUpdate(String sql) throws SQLException
{
try {
conn.setAutoCommit(false);
int re = stmt.executeUpdate(sql);
conn.commit();
return re;
}
catch (SQLException e) {
conn.rollback();
System.out.println("Error occured when update database:" + e);
throw e;
}
}
public ResultSet executeQuery() throws SQLException
{
try {
return ps.executeQuery();
}
catch (SQLException e) {
System.out.println("Error occured when query database:" + e);
throw e;
}
}
public int executeUpdate() throws SQLException
{
try {
conn.setAutoCommit(false);
int r = ps.executeUpdate();
conn.commit();
return r;
}
catch (SQLException e) {
conn.rollback();
System.out.println("Error occured when update database:" + e);
throw e;
}
}
public boolean closeDB() throws SQLException
{
try {
if (this.rs != null)
rs.close();
if (this.stmt != null)
this.stmt.close();
if (this.ps != null)
this.ps.close();
if (this.conn != null)
conn.close();
return true;
}
catch (SQLException e) {
System.out.println("Error occured when close database:" + e);
throw e;
}
}
}
求解,真的不懂,谢谢!
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:5
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

java.lang.NullPointerException
net.chat.BaseConn.preparedStatement(BaseConn.java:43)
net.chat.CheckLogin.checklogin(CheckLogin.java:33)
org.apache.jsp.chklogin_jsp._jspService(chklogin_jsp.java:100)
展开
 我来答
wuhen_zhang
2014-03-31 · TA获得超过736个赞
知道小有建树答主
回答量:253
采纳率:0%
帮助的人:46.1万
展开全部
jdbc驱动:mysql-connector-java-5.1.29-bin.jar怎么用啊?
你需要把这个jar包导入到项目里面,然后你就可以使用包里的类和函数了。
更多追问追答
追问
已经放了,但是数据库接不上。原来这个程序是接SqlServer2005的,我的是MySQL,想改成MYSQL,但是不会改。。一直接不上数据库
已经放了,但是数据库接不上。原来这个程序是接SqlServer2005的,我的是MySQL,想改成MYSQL,但是不会改。。一直接不上数据库
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式