我是一个新的程序员。如果你能帮我解决编码中的这些错误,我将不胜感激?
我随函附上错误信息和一些与错误相关的编码部分。
这些是发生的错误。
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at beacco.operation_det.OperationNo(operation_det.java:52)
at beacco.operation_det.<init>(operation_det.java:34)
第52行-->public void operationno()第34行-->operationno()///在connect()之后;
这是我的密码。
import java.awt.HeadlessException;
import java.io.PrintWriter;
import static java.lang.System.out;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public final class operation_det extends javax.swing.JFrame {
public operation_det()
{
initComponents();
Connect();
OperationNo();
}
Connection conn;
PreparedStatement pst;
public void Connect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/beaccodb?zeroDateTimeBehavior=convertToNull","root","");
JOptionPane.showMessageDialog(null, "Connected");
}
catch (ClassNotFoundException | SQLException | HeadlessException e)
{
JOptionPane.showMessageDialog(null, e+" Error in Connecting to database");
}
}
public void OperationNo()
{
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select MAX(operation_mo) from operation");
rs.next();
rs.getString("MAX(operation_no");
if (rs.getString("MAX(operation_no")== null)
{
operation_no.setText("00000");
}
else
{
long id = Long.parseLong(rs.getString("MAX(operation_no").substring(2,rs.getString("MAX(operation_no").length()));
id++;
operation_no.setText(String.format("%07d",id));
}
}
catch (SQLException ex)
{
Logger.getLogger(operation_det.class.getName()).log(Level.SEVERE, null, ex);
}
}```
暂无答案!
目前还没有任何答案,快来回答吧!