用xml文件
<?xml version="1.0" encoding="gb2312"?><db-info> <db> <driver>net.sourceforge.jtds.jdbc.Driver</driver> <url>jdbc:jtds:sqlserver://localhost:1433;DatabaseName=et</url> <user>test</user> <pass>test</pass> </db></db-info>SAXBuilder builder = new SAXBuilder(); Document read_doc;
try {
read_doc = builder.build("dbinfo.xml");
Element stu = read_doc.getRootElement();
List list = stu.getChildren("db");
for (int i = 0; i < list.size(); i++) { Element e = (Element) list.get(i);
String str_driver=e.getChildText("driver");
this.driver=str_driver;
String str_url = e.getChildText("url");
this.url=str_url; String str_user = e.getChildText("user");
this.user=str_user;
String str_pass = e.getChildText("pass");
this.pass=str_pass;
if(logger.isInfoEnabled()){
logger.info("DbTool() - dbinfo : str_driver = "
+ str_driver); logger.info("DbTool() -dbinfo : String str_url = " + str_url); logger.info("DbTool() -dbinfo : str_user = " + str_user);
logger.info("DbTool() -dbinfo :str_pass = " + str_pass);
}
}
} catch (JDOMException e1) { e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
D:\Tomcat 4.1\webapps\cs\java\aa.java:20: cannot resolve symbol
symbol : class SAXBuilder
location: class aa
SAXBuilder builder = new SAXBuilder();
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:20: cannot resolve symbol
symbol : class SAXBuilder
location: class aa
SAXBuilder builder = new SAXBuilder();
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:22: cannot resolve symbol
symbol : class Document
location: class aa
Document read_doc;
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:25: cannot resolve symbol
symbol : class Element
location: class aa
Element stu = read_doc.getRootElement();
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:26: reference to List is ambiguous, both class java.awt.List in java.awt and class java.util.List in java.util match
List list = stu.getChildren("db");
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:27: operator < cannot be applied to int,java.awt.Dimension
for (int i = 0; i < list.size(); i++)
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:31: cannot resolve symbol
symbol : class Element
location: class aa
Element e = (Element) list.get(i);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:31: cannot resolve symbol
symbol : class Element
location: class aa
Element e = (Element) list.get(i);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:31: cannot resolve symbol
symbol : method get (int)
location: class java.awt.List
Element e = (Element) list.get(i);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:35: non-static variable this cannot be referenced from a static context
this.driver=str_driver;
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:38: non-static variable this cannot be referenced from a static context
this.url=str_url;
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:41: non-static variable this cannot be referenced from a static context
this.user=str_user;
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:45: non-static variable this cannot be referenced from a static context
this.pass=str_pass;
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:49: cannot resolve symbol
symbol : variable logger
location: class aa
if(logger.isInfoEnabled()){
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:51: cannot resolve symbol
symbol : variable logger
location: class aa
logger.info("DbTool() - dbinfo : str_driver = " + str_driver);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:53: cannot resolve symbol
symbol : variable logger
location: class aa
logger.info("DbTool() -dbinfo : String str_url = " + str_url);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:55: cannot resolve symbol
symbol : variable logger
location: class aa
logger.info("DbTool() -dbinfo : str_user = " + str_user);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:57: cannot resolve symbol
symbol : variable logger
location: class aa
logger.info("DbTool() -dbinfo :str_pass = " + str_pass);
^
D:\Tomcat 4.1\webapps\cs\java\aa.java:66: cannot resolve symbol
symbol : class JDOMException
location: class aa
catch (JDOMException e1) {
^
Note: D:\Tomcat 4.1\webapps\cs\java\aa.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
19 errors
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.sql.*;public class a
{
SAXBuilder sb=new SAXBuilder();
Document doc=sb.build("dbinfo.xml");
Element root=doc.getRootElement();
List list=root.getChildren("db");
for(int i=0;i<list.size();i++){
Element element=(Element)list.get(i);
public static String dbDriver =element.getChildText("driver");
public static String dbURL =element.getChildText("url");
public static String user =element.getChildText("user");
public static String password =element.getChildText("pass");}D:\Tomcat 4.1\webapps\qygk\WEB-INF\classes\a.java:16: illegal start of type
for(int i=0;i<list.size();i++){
^
D:\Tomcat 4.1\webapps\qygk\WEB-INF\classes\a.java:27: <identifier> expected
}
^
2 errors