使用ojdbc在jsp中将数据输入数据库时​​获取java.lang.NullPointerException

时间:2017-08-18 10:15:12

标签: java oracle jsp

我正在尝试使用jsp将新用户注册到我的数据库。当我这样做我得到这个错误java.lang.NullPointerException

在此页面中,我将变量输入数据库

<%@page import="storage.data"%>
<%
            String ps="";
            String v_name="";


             v_name =request.getParameter("vname");
             ps=request.getParameter("pass");

             data dt=new data();

               out.println(v_name + ps);

               try{

                    dt.st=dt.cn.createStatement();
                    out.println("1");
                    String insert="insert into voters values(myseq_voters.nextval,'"+v_name+"','"+ps+"',sysdate)";
                    out.println("2");
                    dt.st.executeUpdate(insert);
                    out.println("3");
                        //response.sendRedirect("adduser.jsp?usad="+1);
                }
                catch(Exception ex){
                out.println(ex);
                }
%>

这是我将其连接到数据库的代码

package storage;
import java.sql.*;


public class data {

        public Connection cn;
        public Statement st;
        public ResultSet rs;

        public data()
        {
            try{

                Class.forName("oracle.jdbc.OracleDriver");
                //cn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","mustafadb","111");
                //jdbc:oracle:thin:@localhost:1521:XE [system on Default schema]
                cn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","voter_db","111");
            }
            catch(Exception ex){}
        }
}

0 个答案:

没有答案