永发信息网

Caused by: java.sql.SQLDataException: ORA-01840: 输入值对于日期格式不够长

答案:4  悬赏:60  手机版
解决时间 2021-01-22 17:22
  • 提问者网友:了了无期
  • 2021-01-22 10:48
Caused by: java.sql.SQLDataException: ORA-01840: 输入值对于日期格式不够长
最佳答案
  • 五星知识达人网友:胯下狙击手
  • 2021-01-22 12:25
public class test1 extends JFrame implements ActionListener{
JPanel jp1,jp2;
JTable jt1=null;
JLabel jl1=null;
JTextField jtf=null;
JButton jb1,jb2,jb3,jb4;
JTable jt=null;
JScrollPane jsp=null;
//String sql;
public static void main(String[] args) {
test1 t1=new test1();
}
test1(){
jp1=new JPanel();
jl1=new JLabel("请输入要查询的编号");
jtf=new JTextField(10);
jb1=new JButton("查询");

jb1.addActionListener(this);
jp1.add(jl1);
jp1.add(jtf);
jp1.add(jb1);

jp2=new JPanel();
jb2=new JButton("添加");
jb3=new JButton("删除");
jb4=new JButton("修改");
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
tablemodel t=new tablemodel();

jt1=new JTable(t);
jsp=new JScrollPane(jt1);
this.add(jsp);
this.add(jp1,"North");
this.add(jp2,"South");

this.setSize(400,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource()==jb1){

//System.out.println("王博古");

String name=this.jtf.getText().trim();
String sql="select * from lixianqi where name="+"'"+name+"'";
tablemodel t=new tablemodel(sql);
jt.setModel(t);
}
}
}

Vector rowData, columnNames;
Connection connection=null;
PreparedStatement ps=null;
ResultSet res=null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public tablemodel(){

columnNames=new Vector();
columnNames.add("编码");
columnNames.add("版本");
columnNames.add("名字");
rowData=new Vector();
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection=DriverManager.getConnection
("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=zhudan","sa","zhudan");
ps=connection.prepareStatement("select * from lixianqi");
res=ps.executeQuery();

while(res.next()){
Vector v=new Vector();
v.add(res.getInt(1));
v.add(res.getString(2));
v.add(res.getString(3));
rowData.add(v);
}

}catch(Exception e){
e.printStackTrace();

}finally{

try {
if(res!=null)res.close();
if(ps!=null)ps.close();
if(connection!=null)connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}

};
public tablemodel(String sql){

columnNames=new Vector();
columnNames.add("编码");
columnNames.add("版本");
columnNames.add("名字");
rowData=new Vector();
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection=DriverManager.getConnection
("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=zhudan","sa","zhudan");
ps=connection.prepareStatement(sql);
res=ps.executeQuery();

while(res.next()){
Vector ve=new Vector();
ve.add(res.getInt(1));
ve.add(res.getString(2));
ve.add(res.getString(3));
rowData.add(ve);
}

}catch(Exception e){
e.printStackTrace();

}finally{

try {
if(res!=null)res.close();
if(ps!=null)ps.close();
if(connection!=null)connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}
}

//得到多少列
public int getColumnCount() {
System.out.println("a");
return this.columnNames.size();
}
//得到多少列
public int getRowCount() {
System.out.println("2");
return this.rowData.size();
}
//得到哪行哪列
public Object getValueAt(int row, int colum) {
System.out.println("3");
return ((Vector)this.rowData.get(row)).get(colum);
}

public String getColumnName(int column) {
// TODO Auto-generated method stub
return (String) columnNames.get(column);
}

}

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at chack.test1.actionPerformed(test1.java:75)
全部回答
  • 1楼网友:狂恋
  • 2021-01-22 15:41
加载数据库驱动怎么有错啊
  • 2楼网友:独行浪子会拥风
  • 2021-01-22 14:58
找到你本地报错的代码,看看你的日期格式是否正确
  • 3楼网友:十年萤火照君眠
  • 2021-01-22 13:21
贴代码 才能知道什么地方错的
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯