Write test Cases: Test database connection __ Database

Source: Internet
Author: User

Original Dbconfig.txt source code is as follows:

Pool=false

Datasource=java:comp/env/carddata

connurl=jdbc:microsoft:sqlserver://10.0.0.222:1433; User=sa;databasename=cardtest;

Drivername=com.microsoft.jdbc.sqlserver.sqlserverdriver

The original Datatable.java source code is as follows, but in order to invoke convenience, I added the Get method.:

Package pub;

Import Java.sql.ResultSet;

Import Java.sql.ResultSetMetaData;

public class datatable{

Private Java.util.ArrayList fdatalist;

Private Java.util.ArrayList fcolumnlist;

private int fcolumncount;

private int frowcount;

public int getColumnCount () {

return fcolumncount;

}

public int GetRowCount () {

return frowcount;

}

Public DataTable () {

Fdatalist=new java.util.ArrayList ();

Fcolumnlist=new java.util.ArrayList ();

}

public void SetData (ResultSet rs) {

try{

Fdatalist.clear ();

Fcolumnlist.clear ();

ResultSetMetaData Irsm=rs.getmetadata ();

Fcolumncount=irsm.getcolumncount ();

for (int i=0;i<fcolumncount;i++) {

Fcolumnlist.add (Irsm.getcolumnname (i+1). toLowerCase ());

}

Rs.beforefirst ();

while (Rs.next ()) {

DataRow dr=new DataRow ();

for (int i=0;i<fcolumncount;i++) {

String x=rs.getstring (i+1);

if (x==null) x= "";

if (X.equals ("null")) x= "";

Dr.additem (x);

}

Fdatalist.add (DR);

}

Frowcount=fdatalist.size ();

}catch (Exception e) {

}

}

public void Close () {

Fdatalist.clear ();

Fcolumnlist.clear ();

}

Public String getitemforname (int row,string colname) {

try{

if (row>-1 && row<frowcount) {

DataRow dr= (DataRow) fdatalist.get (row);

int Colindex=fcolumnlist.indexof (Colname.tolowercase ());

if (colindex>-1) {

Return Dr.getitem (Colindex);

}

else{

Return "";

}

}

else{

Return "";

}

}

catch (Exception e) {

Return "";

}

}

Public String getitemforindex (int row,int colindex) {

try{

if (row>-1 && row<frowcount) {

DataRow dr= (DataRow) fdatalist.get (row);

Return Dr.getitem (Colindex);

}

else{

Return "";

}

}

catch (Exception e) {

Return "";

}

}

}

The original database connection Conn.java source code is as follows:

Package pub;

Import java.sql.*;

Import java.io.*;

Import java.util.*;

Import Javax.naming.InitialContext;

Import Javax.naming.Context;

Import Javax.sql.DataSource;

public class Conn {

Private Boolean ispool=true;

Private String strdrivername= "";

Private String strconnurl= "";

Private String strdatasource= "";

Private String ferrormsg;

Public String GetLastError ()

{

return ferrormsg;

}

Public String test () {

&

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.