admin 管理员组

文章数量: 1184232


2024年4月20日发(作者:osgb生成s3c索引文件)

XML连接数据库

localhost

1433

mvc

sa

verDriver

jdbc:microsoft:sqlserver://

:

;DatabaseName=

localhost

3306

poi_mvc

root

123456

jdbc:mysql://

:

/

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


本文标签: 连接 生成 数据库 查询 功能