错误:解析时已到达文件末尾 [英] Error: reached end of file while parsing

查看:186
本文介绍了错误:解析时已到达文件末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,我开发了一个具有数据库连接的程序.在我的代码中,我尝试插入数据.对于数据库连接来说不是问题,但是我的代码存在问题,文件解析结束时出现错误.请更正我的代码,因为我可以确定问题是什么.我还突出显示了行,它给了我这个错误..

hai , i am developed a program with database connection. In my code i am try to insert data. For database connection is no probleam but i have probleam with my code which i got an error reached end of file parsing . Please correct my code please cause i can identify what is the probleam is. I also highlight line which give me this error..

import javax.swing.JOptionPane;
import java.sql.*;

  

 public class ActInsertData {

    String userid="saya", password="1234";
	String url="jdbc:odbc:Semester2";
		Statement stmt;
		Connection con;
 
    public void getConnection()
{
try
	{
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	}
catch(java.lang.ClassNotFoundException e)
	{
 	System.err.print("classNotFoundException:");
	System.err.println(e.getMessage());
	}
try
	{
	 con=DriverManager.getConnection(url,userid, password);
	if(con!= null)
	{
 
	System.out.println("Got Connection.");
	DatabaseMetaData meta=con.getMetaData();
	System.out.println("Driver Name: " + meta.getDriverName());
	}
else
 System.out.println("Could not Get Connection");
	}
	catch(SQLException ex)
	{
	
	System.err.println("SQLException: " +ex.getMessage());
	}
}
public void insertData()
{
 
 String insertString1 = "insert into student values('ALI', 15, 'MALE' )";
String  insertString2 = "insert into student values('AHMAD', 16, 'MALE')";
String insertString3 = "insert into student values('AYU, 15,'FEMALE')";
String insertString4 = "insert into student values('ANI', 17,'FEMALE')";

try
{
stmt = con.createStatement();
stmt.executeUpdate(insertString1);
stmt.executeUpdate(insertString2);
stmt.executeUpdate(insertString3);
stmt.executeUpdate(insertString4);
stmt.close();
con.close();
}
catch(SQLException ex)
 {
System.err.println("SQLException: " + ex.getMessage());
}

System.out.println("Data Inserted into Student Table");

public static void main(String[] args) throws Exception/* this is the line which cause an error*/
{
ActInsertData obj = new ActInsertData();
obj.getConnection();
obj.insertData();
}
}

推荐答案

,当函数public static void main(String[] args)出现问题时-则不要启动它.问题解决了.

或更确切地说,没有弄清楚.

上面的代码对文件的解析一无所知.

解析文件时,您始终需要检查是否还有其他要解析的内容:
when the function public static void main(String[] args) is the problem - then you should not start it. Problem solved.

Or rather not figured out correctly.

Your code above says nothing about the parsing of a file.

When you''re parsing a file you always need to check whether there is more to parse:
try {
    BufferedReader oReader = new BufferedReader(oFile);
    String strLine;
    while (true) {
        strLine = oReader.readLine()
        if(strLine==null) break; // nothing to parse -> Job done, exit loop
        process(strLine);
    }
    oReader.close();
} 
catch (IOException e) {

}


这篇关于错误:解析时已到达文件末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆