存储数据库代码有哪些,求vb 录入信息存储到数据库表中的代码VBSQL
来源:整理 编辑:黑码技术 2025-01-15 12:26:13
1,求vb 录入信息存储到数据库表中的代码VBSQL
我支持的是,分开一个模块,写好你的全部需要连接的方法,然后再所有要引用的地方定义下模块然后调用就行,源代码多了点,想要的话加我吧
2,用数组存储SQL数据库数据的JAVA程序代码
给你个我以前做的例子,不完整,仅供参考。//*************************************public ModelAndView add(HttpServletRequest req, HttpServletResponse res) String username = (String) req.getSession().getAttribute("valid_user"); if (username != null) Integer bookid = Integer.parseInt(req.getParameter("bookid")); Integer number = Integer.parseInt(req.getParameter("number")); Integer userid = getUserDAO().findByName(username).getId(); this.shopcartDAO.addUserBook(userid, bookid, number); Shopcart[] orders = this.getShopcartDAO().findUserBook(userid); return new ModelAndView(this.getMemberPage(), "orders", orders); } else return new ModelAndView(new RedirectView(getRedirectPage())); } }//******************************************************* public void addUserBook(Integer userid,Integer bookid,Integer number) try Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) // TODO Auto-generated catch block e.printStackTrace(); } String sql = "insert into shopcart(userid,bookid,number) " + "values(" + userid + "," + bookid + "," + number + ")"; Connection conn = null; Statement stmt = null; try conn = dataSource.getConnection(); stmt = conn.createStatement(); stmt.execute(sql); } catch(SQLException ex) ex.printStackTrace(); } finally try stmt.close(); } catch(SQLException e1) e1.printStackTrace(); } try conn.close(); } catch(SQLException e2) e2.printStackTrace(); } } }搜一下:用数组存储SQL数据库数据的JAVA程序代码
3,数据库求代码
<%dim conn,connstr,dbstr dbstr="../dywy_data/#dywy_data.mdb" set conn=createobject("adodb.connection") connstr="provider=microsoft.jet.oledb.4.0;data source="& server.mappath(dbstr) conn.open connstr %> 把第二行中的数据库路径改成你数据库路径就可以了。对于SQL Server数据库,C++使用MFC库,主要有两种方法可以连接sql数据库1.利用ADO连接:#import "msado15.dll" no_namespace rename("EOF", "EndOfFile") //必须import这个dll,这个文件通常放在C:\Program Files\Common Files\System\ado路径下._ConnectionPtr m_ptrConnection; //数据库连接对象构造函数中添加如下语句m_ptrConnection = NULL; ::CoInitialize(NULL); //连接数据库的主要代码BOOL DataVisitor::ConnectDataBase(_bstr_t connectionStr) /* Added by stone. If IDOConnection has not been set up,then create one. */ if(m_ptrConnection == NULL) HRESULT hr = m_ptrConnection.CreateInstance(__uuidof(Connection)); if (FAILED(hr)) return FALSE; } else _bstr_t strConnect = connectionStr; //"Provider=SQLOLEDB;Server=(local);Database=navigation; uid=sa; pwd=3277625;"; m_ptrConnection->CursorLocation = adUseClient; m_ptrConnection->IsolationLevel = adXactReadCommitted; try m_ptrConnection->Open(strConnect,"","",adModeUnknown); return TRUE; } catch (_com_error e) // AfxMessageBox((char *)e.Description()); return FALSE; } } } return TRUE;}2. 利用ODBC连接#include CDaoDatabase *MyDataBase; BOOL MyDB_OperSqL::Open_MyDatabase(CString connstr) { try { if (MyDataBase == NULL) { MyDataBase = new CDaoDatabase(); } MyDataBase->Open(NULL,0,0,connstr); } catch( CDaoException* e ) { CString message = _T("MyDB_OperSqL 数据库异常: "); message += e->m_pErrorInfo->m_strDescription; char info[400]; sprintf(info,message); DispErrorMessage(info,__LINE__); e->Delete( ); return FALSE; } catch (CMemoryException *e) { DispErrorMessage("MyDB_OperSqL 内存异常!",__LINE__); e->Delete( ); return FALSE; } catch(...) { DispErrorMessage("MyDB_OperSqL 其它异常!",__LINE__); return FALSE; } return TRUE; } 这里的连接字符串connstr一般是如下内容 "ODBC;DRIVER={SQL Server};SERVER=(local);DATABASE=yourDataBase;UID=yourID;PWD=yourPassword" 如果直接用Microsoft ADO Datebase Control控件的话,连接字串可以自己生成,在控件的属性里面找到拷贝就行,这种最简单
文章TAG:
存储数据库代码有哪些 求vb 录入信息存储到数据库表中的代码VBSQL