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

packagenet.chat;importjava.sql.*;importjava.lang.ClassNotFoundException;publicclassBaseConn{privateConnectionconn=null;privateStatementstmt=null;privatePreparedStatementp...

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)

展开

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:1024 设计师:我叫白小胖 返回首页

打赏作者

栩栩少根筋

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值