远程调用方法:
Server
name:
你的远程服务器URL
User
name:
你的用户名(mysql远程数据)
Database
name:
xxxx42
你的用户名(mysql远程数据)
MySQL
password:xxxxxxxxx2
你的密码(mysql远程数据)
就这么简单
视图说简单点 它就是个表
你是如何 *** 作表的就如何 *** 作视图
我在SQL2008下已经成功执行,不知道你是如何执行,查看下是否是列名没写正确,你的题目上的列名就有错误
(图中的红线警告是说不能在单表情况下绑定多项,但是可以执行)
Java调用存储过程的方法是通过调用Connection的实例方法prepareCall,prepareCall方法返回CallableStatement对象用于填充存储过程的参数。prepareCall方法形参是调用存储过程的sql语句,此参数的语法格式如下:
{call storedProcedureName(parameter-list)}其中,storedProcedureName是存储过程名称,parameter-list是存储过程参数列表。
例如,存储过程名为usp_test,有两个输入参数a,b。则调用代码看起来如下所示:
CallableStatement callableStatement = connectionprepareCall("{call usp_test(,)}");callableStatementsetObject("a","value-1");
callableStatementsetObject("b","value-2");
callableStatementexecute();
下面的例子就是调用通用类的数据库 *** 作方法(数据库的链接与关闭都在通用类中),不懂得花可以发例子给你。using System;
using SystemCollectionsGeneric;
using SystemText;using TroubledTimesModels;
using SystemData;
using SystemDataSqlClient;namespace TroubledTimesDAL
{
/// <summary>
/// 官方活动信息数据访问类
/// </summary>
public static class FunctionsService
{
/// <summary>
/// 1根据不同情况查询活动信息
/// </summary>
/// <param name="type">活动类型</param>
/// <param name="state">设置状态</param>
/// <param name="name">活动名称</param>
/// <param name="flag">控制变量</param>
/// <returns>活动信息对象的集合</returns>
public static IList<Functions> GetAllFunctions(string type,string state,string name,int flag)
{
string sql = "Select from Functions where State =1";
if(type!="" && flag==1)
sql += " and FunState='" + type + "'";
else if (state != "" && flag == 2)
sql += " and SetState='" + state + "'";
else if (name!="" && flag==3)
sql += " and FunctionName like '%" + name + "%'";
else if (flag == 4)
sql += " and FunState='" + type + "' and SetState='" + state + "'";
else if (flag == 5)
sql += " and FunState='" + type + "' and FunctionName like '%" + name + "%'";
else if (flag == 6)
sql += " and SetState='" + state + "' and FunctionName like '%" + name + "%'";
else if (flag == 7)
sql += " and FunState='" + type + "' and SetState='" + state + "' and FunctionName like '%" + name + "%'";
sql += " order by FunNumber Desc";
IList<Functions> list = new List<Functions>();
try
{
// DataTable dt = DBHelperGetScalar("up_SelectFunctions");
DataTable dt = DBHelperGetDataTable(sql);
foreach (DataRow row in dtRows)
{
Functions function = new Functions();
functionFunctionName = (string)row["FunctionName"];
functionFId = (int)row["FId"];
functionFunctionUrl = (string)row["FunctionUrl"];
functionFunctionImg = (string)row["FunctionImg"];
functionFunctionContent = (string)row["FunctionContent"];
functionFunctionTime = (DateTime)row["FunctionTime"];
functionFunAdminUrl = (string)row["FunAdminUrl"];
functionFunState = (int)row["FunState"]; //--活动类型(游戏活动/官网活动,0:游戏)<后加>
functionSetState = (int)row["SetState"]; //--设置状态(设置中/预设置,0:预设置)<后加>
functionFunNumber = (int)row["FunNumber"]; //--活动支持率(仅官网)<后加>
functionState = (int)row["State"]; //--存贮状态(0/1)
listAdd(function);
}
return list;
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return null;
}
} /// <summary>
/// 2根据活动类型获取活动信息
/// </summary>
/// <param name="id">活动类型</param>
/// <returns>该活动类型的数量</returns>
public static int GetFunctionsByType(int type)
{
IList<Functions> list = new List<Functions>();
try
{
string sql = "select count() from Functions where SetState = 1 and FunState='" + type+ "'";
return DBHelperSanlar(sql); }
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
}
} /// <summary>
/// 3根据活动ID修改活动信息
/// </summary>
/// <param name="f">活动信息类对象</param>
/// <returns>数据库中受影响的行数</returns>
public static int ModifyFunctionsById(Functions f)
{
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@FId",fFId),
new SqlParameter("@FunctionName",fFunctionName),
new SqlParameter("@FunctionUrl",fFunctionUrl),
new SqlParameter("@FunctionImg",fFunctionImg),
new SqlParameter("@FunctionContent",fFunctionContent),
new SqlParameter("@FunctionTime",fFunctionTime),
new SqlParameter("@functionFunAdminUrl",fFunAdminUrl),
new SqlParameter("@FunState",fFunState),
new SqlParameter("@FunNumber",fFunNumber),
new SqlParameter("@SetState",fSetState),
new SqlParameter("@State",fState)
};
return DBHelperExecuteProc("up_AmendFunctions", para);
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
}
} /// <summary>
/// 4添加活动信息
/// </summary>
/// <param name="f">活动信息类对象</param>
/// <returns>数据库中受影响的行数</returns>
public static int AddFunctions(Functions f)
{
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@FunctionName",fFunctionName),
new SqlParameter("@FunctionUrl",fFunctionUrl),
new SqlParameter("@FunctionImg",fFunctionImg),
new SqlParameter("@FunctionContent",fFunctionContent),
new SqlParameter("@FunctionTime",fFunctionTime),
new SqlParameter("@FunAdminUrl",fFunAdminUrl),
new SqlParameter("@FunState",fFunState),
new SqlParameter("@FunNumber",fFunNumber),
new SqlParameter("@SetState",fSetState),
new SqlParameter("@State",fState) };
return DBHelperExecuteProc("up_AddFunctions", para);
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
} }
/// <summary>
/// 5、根据id批量删除活动信息(修改)
/// </summary>
/// <param name="id">活动信息id</param>
/// <returns>返回受影响的行数</returns>
public static int DeleteFunById(string ids)
{
//string sql = "update Functions set State = 0 where FId in('"+ids+"')";
string sql = "update Functions set State = 0 where FId ='" + ids + "'";
try
{
return DBHelperExecuteCommand(sql);
}
catch(Exception ex)
{
throw ex;
}
}
/// <summary>
/// 6、根据id修改设置状态
/// </summary>
/// <param name="id">活动信息id</param>
/// <returns>返回受影响的行数</returns>
public static int UpdateSetById(int id, int setState)
{
string sql = "Update Functions set SetState = "+setState+" where FId="+id;
try
{
return DBHelperExecuteCommand(sql);
}
catch(Exception ex)
{
throw ex;
}
}
}
}
一般都使用JDBC(Java Data Base Connection)来实现数据库的增删改查,其他的hibernate什么的底层实现还是jdbc,以JDBC为例,首先你要知道数据库类型(注册驱动),然后根据数据库类型取得一个什么地方上的数据库的链接(取得链接),然后建立你要执行的 *** 作(执行 *** 作),最后对 *** 作结果进行处理,然后关闭链接释放资源就可以了。以SQL server为例。
Connection con=null;
Statement stmt = null;
ResultSet rs = null;
try {
String sql = "select id,name from users ";
DriverManagerregisterDriver(new netsourceforgejtdsjdbcDriver);//注册驱动,说明是什么数据库
con = DriverManagergetConnection("jdbc:jtds:sqlserver://localhost:1433/test1", "sa", "123456");//取得链接,说明我从哪里查询
stmt = concreateStatement();//创建 *** 作对象
rs = stmtexecuteQuery(sql);//执行 *** 作
while (rsnext()) {
Systemoutprintln(rsgetString("id")+ ":"+rsgetString("name"));//处理结果
}
} catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}catch(IOException e){
eprintStackTrace();
}
finally {//关闭资源 释放链接
try {
if (rs != null) {
rsclose();
rs = null;
}
if (stmt != null) {
stmtclose();
stmt = null;
}
if (con != null) {
conclose();
con = null;
}
} catch (SQLException e) {
eprintStackTrace();
}
}
OVER
以上就是关于mysql远程数据库怎么调用全部的内容,包括:mysql远程数据库怎么调用、创建了数据库视图 然后怎么调用、java中如何调用数据库的存储过程等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)