admin 管理员组文章数量: 1184232
2024年4月20日发(作者:osgb生成s3c索引文件)
XML连接数据库
XML_SQL_(与数据库建立连接)
package SQLBean;
import s.*;
import .*;
import .*;
public class XML_SQL_BEAN
{
String url; String cfn; String ip; String port; String dbn; String dbname;
String use; String pass; String temp; Connection con=null; Statement sta=null;
public XML_SQL_BEAN() throws Exception {
1
DocumentBuilderFactory factory = tance();
DocumentBuilder builder = umentBuilder();
Document doc = ("");
NodeList nl = mentsByTagName("User");
for (int i = 0; i < gth(); i++) {
Element node = (Element) (i);
ip = mentsByTagName("IP").item(0).getFirstChild() .getNodeValue();
port = mentsByTagName("Port").item(0).getFirstChild().getNodeValue();
dbname = mentsByTagName("DBName").item(0).getFirstChild().getNodeValue();
use = mentsByTagName("UserName").item(0).getFirstChild() .getNodeValue();
if (mentsByTagName("PassWord").item(0).getFirstChild() == null) {
pass = "";
} else {
pass = mentsByTagName("PassWord").item(0) .getFirstChild().getNodeValue();
break;
}
}
nl = mentsByTagName("DataBase");
for (int i = 0; i < gth(); i++) {
Element node = (Element) (i);
if (!"on".equalsIgnoreCase(ribute("type")))
continue;
cfn = mentsByTagName("ClassForName").item(0)
.getFirstChild().getNodeValue();
url = mentsByTagName("URL").item(0).getFirstChild()
.getNodeValue();
temp = mentsByTagName("Temp").item(0).getFirstChild()
.getNodeValue();
dbn = mentsByTagName("DataBaseName").item(0)
.getFirstChild().getNodeValue();
break;
}
e(cfn);
String str = null;
str = (url + ip + temp + port + dbn + dbname);
con = nection(str, use, pass);
sta = Statement();
}
Statement getStatement() {
return sta;
}
}
XML_SQL_(增,删,改功能)
package SQLBean;
2
import .*;
public class XML_SQL_Change
{
Statement sta=null;
public XML_SQL_Change()throws Exception
{
sta=new XML_SQL_BEAN().getStatement();
}
public void updata(String sql)throws Exception
{
eUpdate(sql);
}
}
XML_SQL_(查询功能)
package SQLBean;
import .*;
public class XML_SQL_ResultSet
{
Statement sta=null;
public XML_SQL_ResultSet()throws Exception
{
sta=new XML_SQL_BEAN().getStatement();
}
public ResultSet select(String select)throws Exception
{
return eQuery(select);
}
}
(测试连接)
import _SQL_BEAN;
import _SQL_ResultSet;
import .*;
public class trySQL
{
public static void main(String[] args)
{
try
{
XML_SQL_ResultSet sql=new XML_SQL_ResultSet();
ResultSet res=("select * from student");
while(())
{
n(ing(2));
}
3
}
}
}
catch (Exception e)
{
tackTrace();
}
4
版权声明:本文标题:XML连接数据库(ok) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1713605269a642966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论