mongodb数据库安装包里集合怎么存储的

mongodb数据库安装包里集合怎么存储的,第1张

1)列出当前的数据库

MongoDB shell version: 181

connecting to: test

> show dbs ->

有关更多信息,请参见 TableAdapter 概述。若要保存对象集合中的数据,请循环通过对象集合(例如,for-next 循环),然后使用 TableAdapter 的 DBDirect 方法之一将每个对象的值发送到数据库中。默认情况下,DBDirect 方法在 TableAdapter 上创建,能够直接对数据库执行 *** 作。这些方法可以直接调用,它们不要求 DataSet 或DataTable 对象来协调更改即可将更新发送到数据库。注意配置TableAdapter 时,主查询必须提供足够的信息,才能创建 DBDirect 方法。例如,如果将 TableAdapter 配置为从未定义主键列的表中查询数据,它将不会生成 DBDirect 方法。 TableAdapter DBDirect 方法 说明TableAdapterInsert向数据库中添加新记录,此方法允许将值作为方法参数传入各个列。TableAdapterUpdate更新数据库中的现有记录。Update 方法将原始列值和新列值用作方法参数。原始值用于定位原始记录,新值用于更新该记录。通过将 DataSet、DataTable、DataRow、或 DataRow 数组用作方法参数,TableAdapterUpdate 方法还可用于将数据集中的更改协调回数据库。TableAdapterDelete在基于作为方法参数传入的原始列值的数据库中,删除其现有记录。将对象中的新记录保存到数据库中通过将值传递给 TableAdapterInsert 方法可创建这些记录。下面的示例通过将 currentCustomer 对象中的值传递给 TableAdapterInsert 方法,在 Customers 表中创建一项新的客户记录。 Visual Basic PrivateSub AddNewCustomer(ByVal currentCustomer As Customer) CustomersTableAdapterInsert( _ currentCustomerCustomerID, _ currentCustomerCompanyName, _ currentCustomerContactName, _ currentCustomerContactTitle, _ currentCustomerAddress, _ currentCustomerCity, _ currentCustomerRegion, _ currentCustomerPostalCode, _ currentCustomerCountry, _ currentCustomerPhone, _ currentCustomerFax) EndSub C# privatevoid AddNewCustomers(Customer currentCustomer) { customersTableAdapterInsert( currentCustomerCustomerID, currentCustomerCompanyName, currentCustomerContactName, currentCustomerContactTitle, currentCustomerAddress, currentCustomerCity, currentCustomerRegion, currentCustomerPostalCode, currentCustomerCountry, currentCustomerPhone, currentCustomerFax); } J# privatevoid AddNewCustomers(Customer currentCustomer) { northwindDataSetCustomersTableAdapterInsert( currentCustomerget_CustomerID(), currentCustomerget_CompanyName(), currentCustomerget_ContactName(), currentCustomerget_ContactTitle(), currentCustomerget_Address(), currentCustomerget_City(), currentCustomerget_Region(), currentCustomerget_PostalCode(), currentCustomerget_Country(), currentCustomerget_Phone(), currentCustomerget_Fax()); }将对象中的现有记录更新到数据库修改记录:调用 TableAdapterUpdate 方法并传入新值可更新记录,而传入原始值可定位记录。注意对象需要保留其原始值,才能将它们传递给 Update 方法。此示例使用前缀为 orig 的属性存储原始值。下面的示例通过将 Customer 对象中的新值和原始值传递给 TableAdapterUpdate 方法,更新 Customers 表中的现有记录。 Visual Basic PrivateSub UpdateCustomer(ByVal cust As Customer) CustomersTableAdapterUpdate( _ custCustomerID, _ custCompanyName, _ custContactName, _ custContactTitle, _ custAddress, _ custCity, _ custRegion, _ custPostalCode, _ custCountry, _ custPhone, _ custFax, _ custorigCustomerID, _ custorigCompanyName, _ custorigContactName, _ custorigContactTitle, _ custorigAddress, _ custorigCity, _ custorigRegion, _ custorigPostalCode, _ custorigCountry, _ custorigPhone, _ custorigFax) EndSub C# privatevoid UpdateCustomer(Customer cust) { customersTableAdapterUpdate( custCustomerID, custCompanyName, custContactName, custContactTitle, custAddress, custCity, custRegion, custPostalCode, custCountry, custPhone, custFax, custorigCustomerID, custorigCompanyName, custorigContactName, custorigContactTitle, custorigAddress, custorigCity, custorigRegion, custorigPostalCode, custorigCountry, custorigPhone, custorigFax); } J# privatevoid UpdateCustomer(Customer cust) { northwindDataSetCustomersTableAdapterUpdate( custget_CustomerID(), custget_CompanyName(), custget_ContactName(), custget_ContactTitle(), custget_Address(), custget_City(), custget_Region(), custget_PostalCode(), custget_Country(), custget_Phone(), custget_Fax(), custget_origCustomerID(), custget_origCompanyName(), custget_origContactName(), custget_origContactTitle(), custget_origAddress(), custget_origCity(), custget_origRegion(), custget_origPostalCode(), custget_origCountry(), custget_origPhone(), custget_origFax()); }删除数据库中的现有记录通过调用 TableAdapterDelete 方法并传入原始值定位记录,可删除记录。注意对象需要保留其原始值,才能将它们传递给 Delete 方法。 Visual Basic PrivateSub DeleteCustomer(ByVal cust As Customer) CustomersTableAdapterDelete( _ custorigCustomerID, _ custorigCompanyName, _ custorigContactName, _ custorigContactTitle, _ custorigAddress, _ custorigCity, _ custorigRegion, _ custorigPostalCode, _ custorigCountry, _ custorigPhone, _ custorigFax) EndSub C# privatevoid DeleteCustomer(Customer cust) { customersTableAdapterDelete( custorigCustomerID, custorigCompanyName, custorigContactName, custorigContactTitle, custorigAddress, custorigCity, custorigRegion, custorigPostalCode, custorigCountry, custorigPhone, custorigFax); } J# privatevoid DeleteCustomer(Customer cust) { northwindDataSetCustomersTableAdapterDelete( custget_origCustomerID(), custget_origCompanyName(), custget_origContactName(), custget_origContactTitle(), custget_origAddress(), custget_origCity(), custget_origRegion(), custget_origPostalCode(), custget_origCountry(), custget_origPhone(), custget_origFax()); }安全您必须具有相应的权限,才能对数据库中的表执行选定的 INSERT、UPDATE 或 DELETE。

请注意看如下代码:

public List getObject(String sql, Object[] object) { //sql执行语句,object是你sql语句里面的参数

List list = new ArrayList();

Connection con = null;

PreparedStatement pre = null;

ResultSet rs = null;

try{

con = C3P0UtilgetInstance()getConnection(); //这是你获得数据库连接,你把这里改成调用你自己写的jdbc方法

pre = conprepareStatement(sql); //执行sql语句

if(object!=null){

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

presetObject(i+1, object[i]); //给sql里面的参数进行赋值

}

}

rs = preexecuteQuery();

while(rsnext()){

Users u = new User();

usetUserName(rsgetString("UserName"));

usetUserPas(rsgetString("UserPas")); listadd(u);

}

}catch(Exception e){

eprintStackTrace();

return null;

}finally{

C3P0Utilclose(con, pre, rs); //关闭数据库资源

}

return list; //返回list集合

}

注意:list里面保存的是User对象的信息

你要获得User对象的信息,那么就要遍历list

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

User u = (User)listget(i); Systemoutprintln("UserName:"+ugetUserName());

Systemoutprintln("UserPas:"+ugetUserPas());

} 上面是针对list里面有很多个User对象,当然list里面只有一个User对象,也是可以的。

如果你的list里面只有一个User,那么可以直接:User u = (User)listget(0);

Systemoutprintln("UserName:"+ugetUserName());

Systemoutprintln("UserPas:"+ugetUserPas());

希望对你有帮助!

以上就是关于mongodb数据库安装包里集合怎么存储的全部的内容,包括:mongodb数据库安装包里集合怎么存储的、ArrayList<Object>集合sqlite数据库、如何:将数据从对象保存到数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10188642.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存