不行啊,还是不行 出现下面这样错误: "ConnBase.java": Error #: 360 : unreported exception: java.io.FileNotFoundException; must be caught or declared to be thrown at line 94, column 33 Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml")); 这是那条调用语句。 在帮帮忙,要不我把源码给你发过去?
package connjdbc;import java.sql.*;/** For JDOM*/ import org.jdom.*; import java.io.*; import java.io.IOException; import java.io.OutputStream; import java.util.*; import org.xml.*; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; /** * <p>Title: First Connect JDBC</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: weity MicroSystem</p> * @author weity * @version 1.0 */public class ConnBase { /**Get System' Title*/ public static String stitle; /**Get DB Name*/ public static String sDbName ; /**Get User Name*/ public static String sUserName ; /**Get User Password*/ public static String sPwd ; public Connection conn; /**Now Data From App's parameters, First<br> * In the future,these var come from *.ini file. Second<br> * at the end,these info come from *.xml file. Third<brx> * */ public ConnBase(String[] args1){ if(args1.length < 1) { System.out.println("you are wrong"); System.exit(0); } else{ //Here is Check! try{ File file = new File("YSCN.xml"); System.out.println ("Ys.xml Path:"+file.getAbsolutePath()); readProfiles(sDbName,sUserName,sPwd); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://PC163OANG:1433;User="+sUserName+ ";Password="+sPwd+";DatabaseName="+sDbName); //Statement s=conn.createStatement(); //System.out.println("Ok!"); } catch(Exception e) { e.printStackTrace(); } } dlgLogin login = new dlgLogin(conn); login.pack(); login.setVisible(true); } public static void main(String[] args) { sDbName = args[0].toString() ; sUserName = args[1].toString() ; sPwd = args[2].toString() ; ConnBase connBase1 = new ConnBase(args); } public void readProfiles(String sDB,String sName,String sPwd){ SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 //File file = new File("YSCN.xml"); String fileName = "F:/00Temp/ConnJDBC/YSCN.xml"; //Document doc = sb.build(new FileInputStream(fileName)); //Document doc = sb.build(new org.xml.sax.InputSource(new FileInputStream(file))); //路径问题,真他马烦人 //Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml")); Document doc = sb.build(new FileInputStream(".\\src\\YSCN.xml")); //F:\==Java MIS System== //加入一条处理指令 ProcessingInstruction pi = new ProcessingInstruction ("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\""); doc.addContent(pi); Element root = doc.getRootElement(); //得到根元素 java.util.List proFile = root.getChildren(); //得到根元素所有子元素的集合 Element title = (Element)proFile.get(0); //得到第一个title元素 stitle = new String( title.getText() ); Element sqlserver = (Element)proFile.get(2); //得到第一个title元素 sDB = sqlserver.getChildText("DBName"); sName = sqlserver.getChildText("user"); sPwd = sqlserver.getChildText("pwd"); } /**/ }各位帮忙看看,还是不好使阿!但是在单个的java文件就没有问题。 还是jbuilder的配置问题。
"ConnBase.java": Error #: 360 : unreported exception: java.io.FileNotFoundException; must be caught or declared to be thrown at line 94, column 33 Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml")); ------------------------------------------------------------------ Jbuilder的意思并不是找不到文件,而是说Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml"));这句话“如果”出现异常,必须捕获“java.io.FileNotFoundException”或者向上抛出异常,这是jbuilder编译器对代码严谨性和可靠性提出的要求。 所以,你只要把这段语句包含到try{}catch{}中就可以了。
出现下面这样错误:
"ConnBase.java": Error #: 360 : unreported exception: java.io.FileNotFoundException; must be caught or declared to be thrown at line 94, column 33 Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml"));
这是那条调用语句。
在帮帮忙,要不我把源码给你发过去?
我用的J2se 1.4
怎么办?在帮帮忙,否则,项目不能进行了。
其次 你的jbuilder有么有引入对应的类包 假如没有 需要在properties里面加入
JBuilder 中的package是这样的,假设你的project目录为prj那么当前目录应当是prj,如果你的xx.xml放在prj下,new FileInputStream("XX.xml");应该没问题,如果放在prj/src下,new FileInputStream(".\\src\\XX.xml");
import org.jdom.*;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import org.xml.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
/**
* <p>Title: First Connect JDBC</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: weity MicroSystem</p>
* @author weity
* @version 1.0
*/public class ConnBase { /**Get System' Title*/
public static String stitle; /**Get DB Name*/
public static String sDbName ; /**Get User Name*/
public static String sUserName ; /**Get User Password*/
public static String sPwd ; public Connection conn; /**Now Data From App's parameters, First<br>
* In the future,these var come from *.ini file. Second<br>
* at the end,these info come from *.xml file. Third<brx>
* */
public ConnBase(String[] args1){
if(args1.length < 1) {
System.out.println("you are wrong");
System.exit(0);
}
else{
//Here is Check!
try{
File file = new File("YSCN.xml");
System.out.println ("Ys.xml Path:"+file.getAbsolutePath());
readProfiles(sDbName,sUserName,sPwd);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://PC163OANG:1433;User="+sUserName+
";Password="+sPwd+";DatabaseName="+sDbName);
//Statement s=conn.createStatement();
//System.out.println("Ok!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
dlgLogin login = new dlgLogin(conn);
login.pack();
login.setVisible(true);
}
public static void main(String[] args) {
sDbName = args[0].toString() ;
sUserName = args[1].toString() ;
sPwd = args[2].toString() ; ConnBase connBase1 = new ConnBase(args); } public void readProfiles(String sDB,String sName,String sPwd){
SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 //File file = new File("YSCN.xml");
String fileName = "F:/00Temp/ConnJDBC/YSCN.xml";
//Document doc = sb.build(new FileInputStream(fileName));
//Document doc = sb.build(new org.xml.sax.InputSource(new FileInputStream(file)));
//路径问题,真他马烦人
//Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml")); Document doc = sb.build(new FileInputStream(".\\src\\YSCN.xml"));
//F:\==Java MIS System==
//加入一条处理指令
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\"");
doc.addContent(pi);
Element root = doc.getRootElement(); //得到根元素
java.util.List proFile = root.getChildren(); //得到根元素所有子元素的集合
Element title = (Element)proFile.get(0); //得到第一个title元素
stitle = new String( title.getText() ); Element sqlserver = (Element)proFile.get(2); //得到第一个title元素
sDB = sqlserver.getChildText("DBName");
sName = sqlserver.getChildText("user");
sPwd = sqlserver.getChildText("pwd");
}
/**/
}各位帮忙看看,还是不好使阿!但是在单个的java文件就没有问题。
还是jbuilder的配置问题。
------------------------------------------------------------------
Jbuilder的意思并不是找不到文件,而是说Document doc = sb.build(new FileInputStream("F:/00Temp/ConnJDBC/YSCN.xml"));这句话“如果”出现异常,必须捕获“java.io.FileNotFoundException”或者向上抛出异常,这是jbuilder编译器对代码严谨性和可靠性提出的要求。
所以,你只要把这段语句包含到try{}catch{}中就可以了。
abnertan 说的极为正确。