C#中添加MySql的问题,请问大佬应该怎么修改,或者给出在C#中使用mysql的语句也行~感谢

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySQLDriverCS;

public DataTable GetDataTable()
{
MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("localhost","t2","Uxie","Sad-Mothday5^&").AsString);
conn.Open();
MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
commn.ExecuteNonQuery();
string sql = "select * from tb1";
MySQLDataAdapter mda = new MySQLDataAdapter(sql,conn);
DataTable dt = new DataTable();
mda.Fill(dt);
conn.Close();
return dt;
}

那个DataTable后面的GetDataTable()一直是红线提醒
命名空间不能直接包含字段或方法之类的成员
请问应该怎么修改???

2个回答

C#中所有的函数都要放在类里面,所以在你的函数外面加上
class XXX
{
你的代码
}
调用
new XXX().GetDataTable();
至于命名空间,倒不是必须有,如果你不写,是默认的。

fight_in_dl
战在春秋 正解
接近 3 年之前 回复

放到一个命名空间去。
http://www.jb51.net/article/41920.htm

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
vs2017+C#+数据库+桌面程序开发+打包
需求:一个桌面软件自带数据库,可以傻瓜式安装 求问:vs2017+C#使用什么数据库方便最后打包呢? 使用的数据库都需要先自己安装一个?位置啥的不影响打包? 纯新手,求大佬给一个比较全面流程的思路方法,跪谢
C# 使用Mysql数据库配置数据源时,可以成功连接但查询报错
是在用VS2017,Web项目的SqlDataSource工具配置数据源时 测试连接成功 ![图片说明](https://img-ask.csdn.net/upload/201710/09/1507564756_108860.png) 用查询生成器执行查询也是成功的 ![图片说明](https://img-ask.csdn.net/upload/201710/10/1507564949_885290.png) 但测试查询却报错 ![图片说明](https://img-ask.csdn.net/upload/201710/10/1507565011_649991.png) 求大佬解答~
[新人向]C# WPF datagrid问题
我建立了一个datagrid,取了名字叫dg1,写了代码,跑了程序不显示是怎么回事,用的ODBC连接的数据库,求大佬帮忙 ``` private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { string sql = "select* from s;"; string constructorString = "Dsn=学生信息;uid=root"; using (OdbcConnection conn = new OdbcConnection(constructorString)) { OdbcDataAdapter oda = new OdbcDataAdapter(sql, conn); DataSet ds = new DataSet(); oda.Fill(ds); dg1.ItemsSource = ds.Tables[0].DefaultView; } } ``` 是不是我哪里少了什么东西??? 这是引用 ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Odbc; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using MySql.Data.MySqlClient; using System.Data; using System.ComponentModel; using System.Drawing; ```
如何在qt上build Mysql drive
楼主系统是win10,最近在研究mysql和qt。 我在尝试用qt连接mysql服务器的时候, qt creator 告诉我说mysql drive no lead. 我去qt 的论坛上面问,人家说现在已经qt不提供mysql的drive,想用要自己搭。给我一个官方的文档,https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows。 问题是,写文档的人估计很久没有装过mysql了,mysql安装器的Custom Install,已经没有Libs & Include Files的选项了。所以我很难确定如何执行cmd代码 ``` cd %QTDIR%\qtbase\src\plugins\sqldrivers qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt" ``` 最后,我选择使用mysql server的文件, ``` cd %QTDIR%\qtbase\src\plugins\sqldrivers qmake -- "MYSQL_INCDIR=C:/MySql/MySQL Server 8.0/include" "MYSQL_LIBDIR=C:/MySql/MySQL Server 8.0/lib" ``` 得到结论, ``` Info: creating stash file C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\.qmake.stash Running configuration tests... Checking for DB2 (IBM)... no Checking for InterBase... no Checking for MySQL... no Checking for OCI (Oracle)... no Checking for ODBC... yes Checking for PostgreSQL... no Checking for SQLite (version 2)... no Checking for TDS (Sybase)... no Done running configuration tests. Configure summary: Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... yes PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt is now configured for building. Just run 'mingw32-make'. Once everything is built, you must run 'mingw32-make install'. Qt will be installed into 'C:\Qt\5.12.6\mingw73_32'. Prior to reconfiguration, make sure you remove any leftovers from the previous build. ``` 我检查了一下qmake log ``` Trying source 5 (type inline) of library mysql ... + cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.12.6\mingw73_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "QMAKE_USE += mysql" "QMAKE_LIBS_MYSQL = C:/MySQL/lib/libmysql.lib" "QMAKE_INCDIR_MYSQL = C:/MySQL/include" C:/Qt/5.12.6/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql > Info: creating stash file C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\.qmake.stash + cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& mingw32-make > g++ -c -fno-keep-inline-dllexport -O2 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\MySQL\include -IC:\Qt\5.12.6\mingw73_32\mkspecs\win32-g++ -o main.o main.cpp > g++ -Wl,-s -Wl,-subsystem,console -mthreads -o mysql.exe main.o -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib -LC:\Utils\postgresql\pgsql\lib C:\MySQL\lib\libmysql.lib > c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: main.o:main.cpp:(.text.startup+0xc): undefined reference to `mysql_get_client_version@0' > collect2.exe: error: ld returned 1 exit status > mingw32-make: *** [Makefile:66: mysql.exe] Error 1 ``` 看来问题是出在了 undefined reference to `mysql_get_client_version@0' mysql看起来并没有进去。有没有熟悉mysql和qt的大佬解答一下。多谢了和最近有用qt的大佬解答一下。
MySQL为何无法读取数据?
代码如下 ``` MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); Console.WriteLine(reader[0].ToString()); ``` 结果提示我这个: ``` Invalid attempt to access a field before calling Read() ``` 我的表也设置好了 ![图片说明](https://img-ask.csdn.net/upload/201911/17/1573960777_850947.png) 求大佬指教!
求大佬告知怎么解决这个程序集的问题,我试了很多种方法还是不行。
未能加载文件或程序集“Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”或它的某一个依赖项。拒绝访问。 . ![图片说明](https://img-ask.csdn.net/upload/201906/05/1559704280_339228.png) . 程序集已添加,下面为报错信息. . ![图片说明](https://img-ask.csdn.net/upload/201906/05/1559704297_186286.png)
如何理解mysql高版本(8)的group by?
``` SELECT a.*,c.orgName AS dutyOrgNames,GROUP_CONCAT(e.userName) AS projectLeaderNames FROM majorProject a LEFT JOIN projectdutyorg b ON (a.id = b.projectId) LEFT JOIN organization c ON (c.id = b.orgId) LEFT JOIN projectleader d ON (d.projectId = a.id) LEFT JOIN userinfo e ON (e.id = d.userId) WHERE 1=1 AND a.isDelete = 0 GROUP BY a.id ``` 这是之前写的一段sql,会提示错误: ``` Expression #23 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dcdb_guangan_190815.c.ORGNAME' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ``` 如果在group by a.id后面加上",c.orgName"则查询成功,但是无法达到之前sql想要的结果。 我尝试解析新group by的用法,最开始同事告诉我使用group by时,必须和select字段一致,或者使用分组函数max之类的。但是我修改代码后: ``` SELECT a.*,GROUP_CONCAT(e.userName) AS projectLeaderNames FROM majorProject a LEFT JOIN projectdutyorg b ON (a.id = b.projectId) LEFT JOIN organization c ON (c.id = b.orgId) LEFT JOIN projectleader d ON (d.projectId = a.id) LEFT JOIN userinfo e ON (e.id = d.userId) WHERE 1=1 AND a.isDelete = 0 GROUP BY a.id ``` 这段sql运行成功了,但让我不解的是a.星号里面包含了很多字段,并没有和group by后面的字段一致。之后我认为,应该是a.id是主键的原因,将a.星号中的一个字段也加上主键标识,出现了错误: ``` Expression #23 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dcdb_guangan_190815.a.RECORDRECORDCREATETIME' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ``` a.RECORDCREATETIME是a.*中的一个字段。 我总结为:如果select字段中存在主键字段,那么必须与group by后面一致。但是问题在于,最开始出现的报错c.orgName,这个字段并不是主键字段。 非常迷惑,望各位大佬解答,在网上搜了一些资料,都只说如何解决,但是解决方案最佳也仅仅是改配置文件,对我来说这样的解决方法不太友好,我希望理解group by的用法,通过修改sql去解决这个问题。
vs2012用my sql动软生成三层架构,如何调用数据库的数据显示到页面,求代码?
我是新手,我不太理解三层架构,不知道该如何在BLL,DAL中添加代码,马上要交程序了,挺急的,希望大佬们能帮我一下,谢谢!!!
MysqlDataAdapter将数据填充到DataTable后行全为null
``` DataSet ds=new DataSet(); DataTable dt=new DataTable(); String connstr="server=localhost;user id=root;password=root;database=legend"; MySqlConnection conn=new MySqlConnection(connstr); conn.Open(); String cmdstr="select * from `character`"; MySqlCommand cmd=new MySqlCommand(cmdstr,conn); MySqlDataAdapter ad=new MySqlDataAdapter(cmd); ad.Fill(ds,"c"); dt=ds.Tables["c"]; ``` ![图片说明](https://img-ask.csdn.net/upload/201906/04/1559635381_631065.png) ![图片说明](https://img-ask.csdn.net/upload/201906/04/1559635500_460274.png) 可以获取到列但是行都为null,求大佬帮忙解答这是什么原因TAT
有大佬帮忙看一下这个死锁怎么形成的吗
按道理主键+RR不会形成死锁啊 ``` InnoDB: * WE ROLL BACK TRANSACTION (1) InnoDB: * (2) WAITING FOR THIS LOCK TO BE GRANTED: InnoDB: * (2) HOLDS THE LOCK(S): InnoDB: * (2) TRANSACTION: InnoDB: InnoDB: * (1) WAITING FOR THIS LOCK TO BE GRANTED: InnoDB: Transactions deadlock detected, dumping detailed information. update examinees set token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtLmNvZGVwa3UuY29tXC9hcGlcL2V4YW1pbmVlXC9sb2dpbiIsImlhdCI6MTU3NjM3MjE4MCwiZXhwIjoxNjEyMzcyMTgwLCJuYmYiOjE1NzYzNzIxODAsImp0aSI6Im15TGZ6NmhqVFJzYTNjb1EiLCJzdWIiOjg4NCwicHJ2IjoiNDY3MGJjYmM4YzU5NTJjZTdmN2ExZjQ4OTliOTU0YzU1YjU2NDMyZCJ9.pIIe2xY-eh_3_HhUOURdj325sq9Od1koOVPlRKZ6hXM', login_count = 7, last_login_at = '2019-12-15 09:09:40', examinees.updated_at = '2019-12-15 09:09:40' where id = 884 1: len 6; hex 0000003d236f; asc =#o;; 5: len 15; hex 38353836343036304071712e636f6d; asc 85864060@qq.com;; 14: len 30; hex 68747470733a2f2f6578616d2d313235333338363431342e66696c652e6d; asc https://exam-1253386414.file.m; (total 92 bytes); 10: len 18; hex 343431333233323030383130303333343131; asc 441323200810033411;; 14: len 30; hex 68747470733a2f2f6578616d2d313235333338363431342e66696c652e6d; asc https://exam-1253386414.file.m; (total 92 bytes); RECORD LOCKS space id 301 page no 83 n bits 88 index PRIMARY of table exam.examinees trx id 4006767 lock_mode X locks rec but not gap waiting Record lock, heap no 12 PHYSICAL RECORD: n_fields 27; compact format; info bits 0 3: len 9; hex e69d8ee59bbde7909b; asc ;; 25: len 4; hex 5d68cbfc; asc ]h ;; 18: len 24; hex e883a1e88081e5b888e280ad203135333237323433333934; asc 15327243394;; 7: len 30; hex 24327924313024526e656676315a48716755427072383455456c71732e45; asc $2y$10$Rnefv1ZHqgUBpr84UElqs.E; (total 60 bytes); mysql tables in use 1, locked 1 LOCK WAIT 19 lock struct(s), heap size 1136, 8 row lock(s), undo log entries 224 3: len 6; hex e69cb1e888aa; asc ;; 7: len 30; hex 243279243130247756783376524c2e38756457306945644f6e5061734f53; asc $2y$10$wVx3vRL.8udW0iEdOnPasOS; (total 60 bytes); * (1) TRANSACTION: 0: len 4; hex 00000374; asc t;; 13: len 0; hex ; asc ;; 22: len 4; hex 00000008; asc ;; 23: len 4; hex 5df58817; asc ] ;; Record lock, heap no 19 PHYSICAL RECORD: n_fields 27; compact format; info bits 0 8: len 1; hex 01; asc ;; 18: len 24; hex e883a1e88081e5b888e280ad203135333237323433333934; asc 15327243394;; 11: len 1; hex 81; asc ;; 13: len 0; hex ; asc ;; 16: len 1; hex 81; asc ;; 20: len 4; hex 00000000; asc ;; 22: len 4; hex 00000004; asc ;; 24: SQL NULL; 6: len 11; hex 3133383032353838323832; asc 13802588282;; 21: len 30; hex 65794a30655841694f694a4b563151694c434a68624763694f694a49557a; asc eyJ0eXAiOiJKV1QiLCJhbGciOiJIUz; (total 337 bytes); 24: SQL NULL; TRANSACTION 4006767, ACTIVE 1426 sec starting index read 19: len 4; hex 00000013; asc ;; RECORD LOCKS space id 301 page no 28 n bits 88 index PRIMARY of table exam.examinees trx id 4005686 lock_mode X locks rec but not gap waiting Record lock, heap no 19 PHYSICAL RECORD: n_fields 27; compact format; info bits 0 MySQL thread id 10516222, OS thread handle 139667263854336, query id 300969200 *.190 exam updating 10: len 18; hex 343431333233323030383130303333343131; asc 441323200810033411;; 11: len 1; hex 81; asc ;; 12: len 4; hex 00000000; asc ;; 16: len 1; hex 81; asc ;; mysql tables in use 1, locked 1 MySQL thread id 10520696, OS thread handle 139667256985344, query id 301142683 *.190 exam updating 26: len 4; hex 5df58817; asc ] ;; 3: len 6; hex e69cb1e888aa; asc ;; 13: len 0; hex ; asc ;; 10: len 18; hex 343430333034323030383032303230343334; asc 440304200802020434;; 12: len 4; hex 00000000; asc ;; 17: len 1; hex 01; asc ;; 15: len 10; hex 323030382d31302d3033; asc 2008-10-03;; 19: len 4; hex 00000013; asc ;; 20: len 4; hex 00000000; asc ;; 7: len 30; hex 243279243130247756783376524c2e38756457306945644f6e5061734f53; asc $2y$10$wVx3vRL.8udW0iEdOnPasOS; (total 60 bytes); 9: len 30; hex 5b2268747470733a5c2f5c2f6578616d2d313235333338363431342e6669; asc ["https://exam-1253386414.fi; (total 205 bytes); 28 lock struct(s), heap size 3520, 28 row lock(s), undo log entries 1850 26: len 4; hex 5df58817; asc ] ;; 23: len 4; hex 5df5863f; asc ] ?;; 17: len 1; hex 02; asc ;; 26: len 4; hex 5df5863f; asc ] ?;; RECORD LOCKS space id 301 page no 28 n bits 88 index PRIMARY of table exam.examinees trx id 4006767 lock_mode X locks rec but not gap 0: len 4; hex 00000374; asc t;; 4: len 9; hex e69e97e7bfa0e78fa0; asc ;; 15: len 10; hex 323030382d30322d3032; asc 2008-02-02;; TRANSACTION 4005686, ACTIVE 1709 sec starting index read 2: len 7; hex 29000001cf11da; asc ) ;; 8: len 1; hex 01; asc ;; 4: len 9; hex e69e97e7bfa0e78fa0; asc ;; 5: len 15; hex 38353836343036304071712e636f6d; asc 85864060@qq.com;; 9: len 30; hex 5b2268747470733a5c2f5c2f6578616d2d313235333338363431342e6669; asc ["https://exam-1253386414.fi; (total 205 bytes); 18: len 24; hex e883a1e88081e5b888e280ad203135333237323433333934; asc 15327243394;; 6: len 11; hex 3138313239393331303638; asc 18129931068;; 14: len 30; hex 68747470733a2f2f6578616d2d313235333338363431342e66696c652e6d; asc https://exam-1253386414.file.m; (total 92 bytes); update examinees set token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtLmNvZGVwa3UuY29tXC9hcGlcL2V4YW1pbmVlXC9sb2dpbiIsImlhdCI6MTU3NjM3MzQ1NCwiZXhwIjoxNjEyMzczNDU0LCJuYmYiOjE1NzYzNzM0NTQsImp0aSI6IlhXWmZNSUdNTjVLSTd6U0kiLCJzdWIiOjE2MjYsInBydiI6IjQ2NzBiY2JjOGM1OTUyY2U3ZjdhMWY0ODk5Yjk1NGM1NWI1NjQzMmQifQ.zUGTJnfnGREKzbkASKjVtPVaac_3bMXXUVuDs7vdDKE', login_count = 4, last_login_at = '2019-12-15 09:30:54', examinees.updated_at = '2019-12-15 09:30:54' where id = 1626 1: len 6; hex 0000003d236f; asc =#o;; 2: len 7; hex 29000001cf11da; asc ) ;; 25: len 4; hex 5d68cbfc; asc ]h ;; 6: len 11; hex 3138313239393331303638; asc 18129931068;; 15: len 10; hex 323030382d31302d3033; asc 2008-10-03;; 23: len 4; hex 5df58817; asc ] ;; 0: len 4; hex 0000065a; asc Z;; 11: len 1; hex 81; asc ;; 12: len 4; hex 00000000; asc ;; 15: len 10; hex 323030382d31302d3033; asc 2008-10-03;; 23: len 4; hex 5df58817; asc ] ;; 0: len 4; hex 0000065a; asc Z;; 9: len 30; hex 5b2268747470733a5c2f5c2f736372617463682d776f726b732d31323533; asc ["https://scratch-works-1253; (total 215 bytes); 21: len 30; hex 65794a30655841694f694a4b563151694c434a68624763694f694a49557a; asc eyJ0eXAiOiJKV1QiLCJhbGciOiJIUz; (total 337 bytes); 16: len 1; hex 81; asc ;; 21: len 30; hex 65794a30655841694f694a4b563151694c434a68624763694f694a49557a; asc eyJ0eXAiOiJKV1QiLCJhbGciOiJIUz; (total 339 bytes); 17: len 1; hex 01; asc ;; 4: len 6; hex e983ade99c9e; asc ;; 5: len 15; hex 31323038383438374071712e636f6d; asc 12088487@qq.com;; 19: len 4; hex 00000013; asc ;; 24: SQL NULL; 2: len 7; hex 38000001a3284a; asc 8 (J;; 20: len 4; hex 00000000; asc ;; 25: len 4; hex 5dea312c; asc ] 1,;; ```
如何使用c++通过ADO调用mysql有参存储过程并获取结果集
先放代码,遇到的问题是 调用mysql**有参**存储过程时获取不到结果集 ``` #include <iostream> #include <atlstr.h> #import "MSADO15.DLL" rename_namespace("ADOCG") rename("EOF","EndOfFile") using namespace ADOCG; using namespace std; int main() { try { HRESULT hr = CoInitialize(NULL); assert(SUCCEEDED(hr));//返回值可判断初始化COM是否成功,请用SUCCEEDED来判断 _CommandPtr m_DBCommand; //命令对象 _RecordsetPtr m_DBRecordset; //记录对象 _ConnectionPtr m_DBConnection; //数据对象 //创建对象 m_DBCommand.CreateInstance(__uuidof(Command)); m_DBRecordset.CreateInstance(__uuidof(Recordset)); m_DBConnection.CreateInstance(__uuidof(Connection)); //效验数据 if (m_DBCommand == NULL) throw TEXT("创建 m_DBCommand 对象失败"); if (m_DBRecordset == NULL) throw TEXT("创建 m_DBRecordset 对象失败"); if (m_DBConnection == NULL) throw TEXT("创建 m_DBConnection 对象失败"); CString m_strConnect; //构造连接 m_strConnect.Format(TEXT("Driver={MySQL ODBC 8.0 Unicode Driver};UID=%s;PWD=%s;DataBase=%s;Persist Security Info=True;Server=%s;Port=%d;Option=3"), "hhh", "123456", "Test", "192.168.1.115", 3306); //打开连接 m_DBConnection->Open(_bstr_t(m_strConnect), L"", L"", adConnectUnspecified); m_DBConnection->CursorLocation = adUseClient; m_DBCommand->ActiveConnection = m_DBConnection; assert(SUCCEEDED(hr));//返回值可判断初始化COM是否成功,请用SUCCEEDED来判断 LONG lParameterCount = m_DBCommand->Parameters->Count; if (lParameterCount > 0L) { for (LONG i = lParameterCount; i > 0; i--) { m_DBCommand->Parameters->Delete(i - 1); } } //添加参数 _ParameterPtr Parameter; Parameter = m_DBCommand->CreateParameter("wServerID", adInteger, adParamInput, sizeof(LONG), _variant_t((LONG)0)); m_DBCommand->Parameters->Append(Parameter); Parameter = m_DBCommand->CreateParameter("wMachineID", adInteger, adParamInput, sizeof(LONG), _variant_t((LONG)0)); m_DBCommand->Parameters->Append(Parameter); m_DBCommand->CommandText = "LoadGameRoomItem2"; m_DBCommand->CommandType = adCmdText; m_DBRecordset = m_DBCommand->Execute(NULL, NULL, adCmdStoredProc); long RecordCount = m_DBRecordset->GetRecordCount(); cout << RecordCount << endl; _variant_t DBVarValue; if (m_DBRecordset->EndOfFile != VARIANT_TRUE) { FieldsPtr RecordFields = m_DBRecordset->GetFields(); DBVarValue = RecordFields->GetItem("ServerID")->GetValue(); WORD wValue = DBVarValue; } } catch (_com_error& ComError) { cout << ComError.Description() << endl; } return 0; } ``` 储存过程如下 ``` CREATE DEFINER=`root`@`%` PROCEDURE `LoadGameRoomItem2`( in wServerID INT, in wMachineID INT ) BEGIN SELECT * from gameroominfo; END ``` 目前遇到的问题就是,怎么也获取不到结果集,RecordCount始终为零(强行读取提示“BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。”并不是 显示没有其实有,而是确实没有结果集),但是如果我将参数去掉 ``` //添加参数 // _ParameterPtr Parameter; // Parameter = m_DBCommand->CreateParameter("wServerID", adInteger, adParamInput, sizeof(LONG), _variant_t((LONG)0)); // m_DBCommand->Parameters->Append(Parameter); // Parameter = m_DBCommand->CreateParameter("wMachineID", adInteger, adParamInput, sizeof(LONG), _variant_t((LONG)0)); // m_DBCommand->Parameters->Append(Parameter); CREATE DEFINER=`root`@`%` PROCEDURE `LoadGameRoomItem2`( ) BEGIN SELECT * from gameroominfo; END ``` 那么则可以获得结果集(RecordCount数量为40,if (m_DBRecordset->EndOfFile != VARIANT_TRUE)判断能进去,ServerID也能读取到),我试过在存储过程前面后面分别加一个update判断过是不是存储过程没执行成功,但是不管有参无参存储过程,两个Updata都走到了,而且不管有参无参直接在数据库调用都是有结果集的 数据库日志如下 ``` 190923 15:32:38 7534 Connect hhh@DESKTOP-989OGGH on Test 7534 Query SET NAMES utf8 7534 Query SET character_set_results = NULL 7534 Query SET SQL_AUTO_IS_NULL = 0 7534 Query select database() 7534 Query select database() 7534 Query SELECT @@tx_isolation 7534 Query set @@sql_select_limit=DEFAULT 7534 Query call LoadGameRoomItem2 7534 Quit 190923 15:47:54 7621 Connect hhh@DESKTOP-989OGGH on Test 7621 Query SET NAMES utf8 7621 Query SET character_set_results = NULL 7621 Query SET SQL_AUTO_IS_NULL = 0 7621 Query select database() 7621 Query select database() 7621 Query SELECT @@tx_isolation 7621 Prepare call LoadGameRoomItem2(?, ?) 7621 Query set @@sql_select_limit=DEFAULT 7621 Execute call LoadGameRoomItem2('0', '0') 7621 Close stmt 7621 Quit ``` 困扰小弟好几天了,希望各位神仙大佬能帮帮小弟T_T ----------------------------------编辑分界线-------------------------------- ![图片说明](https://img-ask.csdn.net/upload/201909/23/1569232509_546308.png)![图片说明](https://img-ask.csdn.net/upload/201909/23/1569232516_421262.png) 如图,是要像这样处理一张表的内容的,单单用output参数是做不到的,主要问题在如果不加参数这些东西是可以读出来的,但是加了参数就获取不到结果集了。。。。
sql语句问题为什么在数据库中文可以执行但在mybatis中就不行求大佬指点 万分感谢
![图片说明](https://img-ask.csdn.net/upload/201811/11/1541929806_283296.jpg) 这可以执行![图片说明](https://img-ask.csdn.net/upload/201811/11/1541929873_596766.png) 但在mybatis中PREPARE texts FROM @a就出现异常错误了 异常是 SQL: SET @a=CONCAT('SELECT a.accout_,a.name,a.birthday_,b.name_j FROM users a,role b,users_role c WHERE a.`id`=c.`user_id` AND b.`id_j`=c.`role` LIMIT ',(1-1)*3,",",3,'') PREPARE texts FROM @a EXECUTE texts ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREPARE texts FROM @a EXECUTE texts' at line 2 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREPARE texts FROM @a EXECUTE texts' at line 2
我做ssm然后做到验证登录的时候出了这个问题
怎么办,我跟着视频老师做的看了两遍了还是没找到错误= =。大佬救救孩子吧 严重: Servlet.service() for servlet [DispatcherServlet] in context with path [/SJLykt] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'db_vote_system' ### The error may exist in file [C:\XXXX\sp\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SJLykt\WEB-INF\classes\config\mybatis\mapper\UserMapper.xml] ### The error may involve ykt.dao.UserDao.findByUserName ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'db_vote_system'] with root cause
ssm数据库连接失败,找了几天没有用,有大佬吗?Error querying database. Could not。。。
# 数据库连接失败 # 驱动没有问题 1.TomcatLocalhost log 报错 ``` ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database! ### The error may exist in file [D:\Users\28606\IdeaProjects\superMarket1\target\superMarket\WEB-INF\classes\mappers\ShopTableDAO.xml] ### The error may involve com.six.mapper.ShopTableDAO.selectByExample ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!] with root cause com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:108) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy33.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) at com.sun.proxy.$Proxy10.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy19.selectByExample(Unknown Source) at com.six.service.ShopTableServiceImpl.selectByExample(ShopTableServiceImpl.java:36) at com.six.controller.ShopTableController.selectByExample(ShopTableController.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) ``` ## 我改了几次dbconfig.properties 问题没有解决 ``` jdbc.jdbcUrl=jdbc:mysql:///shopmanager jdbc.driverClass=com.mysql.cj.jdbc.Driver jdbc.user=root jdbc.password=1234 ``` 1. ![图片说明](https://img-ask.csdn.net/upload/201911/22/1574390022_411774.png) 2. ![图片说明](https://img-ask.csdn.net/upload/201911/22/1574390633_73853.png)
用hibernate等实现:从一数据库复制一条记录,然后修改该记录的某一列,再插入原数据库
目前该功能(简称copyinsert)可以在mysql数据库里用sql语句实现,我想用hibernate实现,大部分都已经完成,感觉在dao层有一些错误,希望大佬帮忙解惑,能够解决者,还可以另外给C币。 例子如下:(ID为自增,非数据库定义内容) ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534872743_640656.png) 数据库原来有三条记录,然后在mysql中输入查询语句: INSERT INTO t_test(NO,NAME,SEX) SELECT REPLACE (NO,'XS1','XS4'),NAME,SEX FROM t_test WHERE NO='XS1'; ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534872784_814889.png) 可以成功在mysql数据库中实现,结果如下: ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534872803_898787.png) (从上面看,在数据库中直接操作是可以的,但是我想用框架实现)我用了hibernate,struts2,Jeasyui框架(基本都不熟练),目前能确定的是dao层的拼接的sql语句是正确的,但是不能实现插入数据库的功能。 系统主界面如下: ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534873318_873663.png) 点击datagrids上面的“复制并插入“按钮,期望实现**复制某一条信息,修改其中一列后再插入数据库中**(例子是,复制XS1信息,将XS1修改为XS99后,再插入原数据库)。主界面jsp关键代码如下: //1."复制并插入信息"按钮作用 $("#deriveBtn").click(function(){ var no1="XS1"; var no2="XS99"; $.post("test_copyinsert.action",{"no1":no1,"no2":no2},function(data){ if(data.success){ //刷新datagrid $("#list").datagrid("load"); //提示 $.messager.show({ title:"提示", msg:"insertcopy成功" }); }else{ $.messager.alert("提示","检索失败:"+data.msg,"error"); } },"json"); }); }); 下面是TestAction部分代码(主要体现copyinsert): package test.action; //copyinsert实现 private String no1; public void setNo1(String no1) {//普通属性驱动,提供set方法进行接收 this.no1 = no1; } private String no2; public void setNo2(String no2) {//普通属性驱动,提供set方法进行接收 this.no2 = no2; } public void copyinsert(){ service.copyinsert(no1,no2); } } 下面是TestServiceImpl部分代码(主要体现copyinsert): package test.service.impl; @Override public void copyinsert(String no1, String no2){ dao.copyinsert(no1,no2); } } 下面是TestDaoImpl部分主要代码(主要体现copyinsert功能): @Override public void copyinsert(String no1, String no2) { // 获取Session Session session = HibernateUtils.getSession(); try { Transaction tx = session.beginTransaction(); String sql="INSERT INTO t_test (NO,NAME,SEX) SELECT REPLACE (NO,"+"'"+no1+"'"+","+"'"+no2+"'"+"),NAME,SEX FROM t_test WHERE NO="+"'"+no1+"'"+";"; SQLQuery sqlQuery = session.createSQLQuery(sql); List list=sqlQuery.list();//就是这一行!!!!! tx.commit(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { // 释放session session.close(); } 其中,在上述TestDaoImpl代码中,我不太清楚“List list=sqlQuery.list();”的作用,但是如果没有添加这一行代码,运行程序(即点击主界面“复制并插入”按钮)后,数据库没有插入值,myeclipse的Console也没有输出任何新的查询语句; 当在上述TestDaoImpl代码中添加“List list = sqlQuery.list(); ”这一行代码后,再点击按钮运行,数据库仍然没有插入值,但是Console输出了查询语句,但是紧接着会报错,mysql数据库也没有成功插进数据,如图: ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534873763_176501.png) ![图片说明](https://img-ask.csdn.net/upload/201808/22/1534873821_414105.png)
使用springcloud 和 连接池 连接orcale数据库报错,折磨一天了,请大佬解救,启动都正常的
数据库使用PLsql可以连接上,ping数据库主机也是通的。找了一天问题了,求大佬解救一下。基本可以排除数据库问题,现在迷了一天了,想早点下班。。。 报错信息: 2018-12-28 17:00:06.350 ERROR 21560 --- [http-nio-9661-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at grp.pt.common.bs.CacheService$$EnhancerBySpringCGLIB$$14ccc726.putMap(<generated>) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.util.PublicSessionUtil.createSession(PublicSessionUtil.java:118) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.util.PublicSessionUtil.initSessionInfo(PublicSessionUtil.java:39) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.util.session.UserSessionFilter.doFilter(UserSessionFilter.java:41) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144] Caused by: java.lang.NullPointerException: null at grp.pt.util.PublicSessionUtil.getDataSourceBeanKey(PublicSessionUtil.java:138) ~[grp-util-com-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at grp.pt.database.DynamicDataSource.determineCurrentLookupKey(DynamicDataSource.java:21) ~[grp-database-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.determineTargetDataSource(AbstractRoutingDataSource.java:196) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:164) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:246) ~[spring-jdbc-4.3.12.RELEASE.jar:4.3.12.RELEASE] ... 46 common frames omitted yml数据库配置内容 ``` dynamicdata: #系统运行模式[Develop, Product] mode: Develop #默认数据源 defaultKey: admdiv jndiName: data-sources: #数据源名: admdiv_年度_区划code admdiv: driverClassName: oracle.jdbc.driver.OracleDriver #url: jdbc:oracle:thin:@localhost:1521:orcl #driverClassName: com.mysql.jdbc.Driver #连接URL,协议+地址+Scheme #url: jdbc:mysql://localhost:3306/gap_ah?useUnicode=true&characterEncoding=utf8&useSSL=false username: yszx2018 #密码 password: a #数据库连接池配置样例 url: jdbc:oracle:thin:@localhost:1521:orcl #连接池的最大连接数,-1为无限制 maxActive: 8 #最大空闲连接数,-1为无限制。注:如果是高负载系统,此值过低时可能会出现连接关闭的同时会打开新连接,连接池失效 maxIdle: 8 #在连接池满的情况下最长等待时间(毫秒),如果超时则抛异常,-1为一直等待 maxWait: -1 #初始连接数 initialSize: 8 #自动回收超时连接 removeAbandoned: true #自动回收超时时间(以秒数为单位) removeAbandonedTimeout: 3600000 #是否要进行检测 testWhileIdle: true #进行检测一个连接是有效的SQL语句,比如oracle是select 1 from dual 而 mysql是 select 1 validationQuery: select 1 from dual #每隔多少时间检测一次,比如每半小时检测一次,总不能总是检测,这会对性能产生影响 timeBetweenEvictionRunsMillis: 180000 #每次检测时,需要检测多少个数据连接,一般设置为与最大连接数一样,这样就可以检测完所有的连接 numTestsPerEvictionRun: 8 #一个数据库连接连接多少时间之外,我们认为其应该不再适用了(可能下一次就会失效了),应该移除并重新建立连接了 minEvictableIdleTimeMillis: 3600000 ```
sql语句没有写错 在执行的时候idea报错了 在workbench里面也可以执行 有没有大佬说一说 谢谢
``` @Select("select user_number,username from dormitory as a"+ " inner join user_dormitory as b on a.dor_id = b.dor_id"+ "inner join user as c on b.student_number = c.user_number"+ "where a.ridgepole = #{ridgepole} and a.unit = #{unit} and a.door_number = #{doorNumber} and b.room_number = #{roomNumber}" ) 报错: Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a.ridgepole = '10' and a.unit = 'A' and a.door_number = '532' and b.room_number ' at line 1 ```
关于SpringBoot+myBatis实体的字段返回前端后格式变化的问题
我的架构是 springBoot(1.5.9)+myBatis ,连接池用的是阿里的druid,以下是配置信息: 启动类: import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import com.github.pagehelper.PageHelper; /** * * @author wangxufei * */ @SpringBootApplication @EnableAutoConfiguration @MapperScan("com.mofangge.mapper") public class MfgAgencyApplication { @Value("${spring.datasource.username}") private String userName; @Value("${spring.datasource.password}") private String password; @Value("${spring.datasource.url}") private String url; @Bean public ServletRegistrationBean druidServletRegistrationBean() { ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(); servletRegistrationBean.setServlet(new StatViewServlet()); servletRegistrationBean.addUrlMappings("/druid/*"); return servletRegistrationBean; } /** * 注册DruidFilter拦截 * * @return */ @Bean public FilterRegistrationBean duridFilterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); Map<String, String> initParams = new HashMap<String, String>(); // 设置忽略请求 initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.setInitParameters(initParams); filterRegistrationBean.addUrlPatterns("/*"); return filterRegistrationBean; } /** * 配置DruidDataSource * * @return * @throws SQLException */ @Bean public DruidDataSource druidDataSource() throws SQLException { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setUsername(userName); druidDataSource.setPassword(password); druidDataSource.setUrl(url); druidDataSource.setMaxActive(100); druidDataSource.setFilters("stat,wall"); druidDataSource.setInitialSize(10); return druidDataSource; } @Bean public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(druidDataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml")); sqlSessionFactoryBean.setTypeAliasesPackage("com.mofangge.model,com.mofangge.dto"); Interceptor[] interceptors = {new PageHelper()}; sqlSessionFactoryBean.setPlugins(interceptors); return sqlSessionFactoryBean.getObject(); } public static void main(String[] args) { SpringApplication.run(MfgAgencyApplication.class, args); } } properties文件: #server #server.port=8080 server.port=8081 #server.port=8099 #server.servlet-path=/agency ## log logging.level.org.springframework.web: error logging.level.com.mofangge:info logging.file:mfg-agency.log # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration) spring.data.jpa.repositories.enabled=true spring.jpa.database=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect spring.jpa.generate-ddl=false spring.jpa.hibernate.ddl-auto=none spring.jpa.open-in-view=true spring.jpa.show-sql=false 现在遇到的问题是: 实体类中的格式 返回到页面后,字段格式变化了,如下图: 实体: ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520274_791208.png) 数据库: ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520307_858101.png) 返回到页面后的值(controller注解了@RestController): ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520354_282352.png) 第二个字母 应该是大写C 结果变成了小写c。 而且有个现象是: 如果你的字段是 sName 那么前端拿到的是sname 如果你的字段是seName 那么前端拿到的就是seName **不会变化** 也就是说 如果驼峰前字母是2个或2个以上 他就按照原来的格式了,不知道具体是什么原因,求大佬教导。 ps: 我试过很多种方法,只有一种有效果 就是给字段注解 @JsonProperty 但是这种方法会造成我的返回值里会有2个 sname 一个是sname 一个是sName 2个字段都是同样的值 给我一种复制的感觉。。
请教一下,到底我的mapper.xml哪里出错了,弄不明白为什么找不到我写的log类
## update一下经大佬提点后如何解决的 可能因为我曾用粗暴的方法改动过Log.java的类名,导致Log类编译出问题了,编译后类文件夹内根本没有Log.class文件。于是我又粗暴地delete了Log类重写了一次,果然没问题了。 顺便百度了一下如何修改类名 https://zhidao.baidu.com/question/340215163.html ## 原问题如下 小白入门程序媛,这个是一个mybatis的关于银行转账的小练习 在写log部分之前,我写的account部分测试过是没有问题的,转账的业务也成功了的。现在是想增加一个记录日志的操作,在数据库log表格添加转账记录,并且利用log4j在硬盘生成log file中记录转账信息。 可是按照同样的套路写了了log实体类后再写logmapper.xml,却出现了以下的错误,后来干脆连mybatis中的别名的部分都去掉了,直接在mapper.xml中使用完整的类名,还是说找不到我写的log类。实在搞不懂是namespace出错了还是怎么滴。。。。 ## 错误信息如下: ``` 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/8.5.42 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server built: Jun 4 2019 20:29:04 UTC 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server number: 8.5.42.0 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Windows 10 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Version: 10.0 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Architecture: amd64 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java Home: C:\Program Files\Java\jdk1.8.0_201\jre 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Version: 1.8.0_201-b09 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Vendor: Oracle Corporation 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: D:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: D:\apache-tomcat-8.5.42 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=D:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=D:\apache-tomcat-8.5.42 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dwtp.deploy=D:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-8.5.42\endorsed 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dfile.encoding=UTF-8 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.6.5]. 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.AprLifecycleListener initializeSSL 信息: OpenSSL successfully initialized [OpenSSL 1.1.1a 20 Nov 2018] 七月 13, 2019 8:47:00 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-nio-8080"] 七月 13, 2019 8:47:00 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 七月 13, 2019 8:47:00 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-nio-8009"] 七月 13, 2019 8:47:00 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 七月 13, 2019 8:47:00 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 828 ms 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service [Catalina] 七月 13, 2019 8:47:00 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/8.5.42 七月 13, 2019 8:47:01 下午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 七月 13, 2019 8:47:02 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 七月 13, 2019 8:47:02 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 七月 13, 2019 8:47:02 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 1377 ms 七月 13, 2019 8:47:32 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [yan.ibbie.servlet.TransferServlet] in context with path [/bank] threw exception org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in yan/ibbie/mapper/logmapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'yan/ibbie/mapper/logmapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'yan.ibbie.pojo.Log'. Cause: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) at yan.ibbie.service.Impl.AccountServiceImpl.transfer(AccountServiceImpl.java:23) at yan.ibbie.servlet.TransferServlet.service(TransferServlet.java:36) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'yan/ibbie/mapper/logmapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'yan.ibbie.pojo.Log'. Cause: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78) ... 26 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'yan/ibbie/mapper/logmapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'yan.ibbie.pojo.Log'. Cause: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120) at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:373) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119) ... 28 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'yan.ibbie.pojo.Log'. Cause: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118) at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:68) at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135) at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128) at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118) ... 31 more Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'yan.ibbie.pojo.Log'. Cause: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120) at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149) at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116) ... 35 more Caused by: java.lang.ClassNotFoundException: Cannot find class: yan.ibbie.pojo.Log at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89) at org.apache.ibatis.io.Resources.classForName(Resources.java:261) at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116) ... 37 more ``` ## mybatis.xml如下: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="logImpl" value="LOG4J"/> </settings> <!-- default填默认使用的environment的id --> <environments default="default"> <!-- environment标签声明一个环境 --> <environment id="default"> <!-- type="JDBC"表示使用原生JDBC事务 --> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/ssm?serverTimezone=GMT%2B8"/> <property name="username" value="root"/> <property name="password" value="1233210"/> </dataSource> </environment> </environments> <mappers> <mapper resource="yan/ibbie/mapper/accountmapper.xml"/> <mapper resource="yan/ibbie/mapper/logmapper.xml"/> </mappers> </configuration> ``` ## accountmapper.xml如下: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="yan.ibbie.mapper.accountmapper"> <!-- 根据账号和密码查询账户信息 --> <select id="selByAccnoPassword" resultType="yan.ibbie.pojo.Account" parameterType="yan.ibbie.pojo.Account"> select * from account where accno=#{accNo} and password=#{password} </select> <!-- 根据账号和姓名查询账户信息 --> <select id="selByAccnoName" resultType="yan.ibbie.pojo.Account" parameterType="yan.ibbie.pojo.Account"> select * from account where accno=#{accNo} and name=#{name} </select> <!-- 根据账号修改账户余额 --> <update id="updBalanceByAccno" parameterType="yan.ibbie.pojo.Account"> update account set balance=balance+#{balance} where accno=#{accNo} </update> </mapper> ``` ## logmapper.xml如下: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="yan.ibbie.mapper.logmapper"> <insert id="insLog" parameterType="yan.ibbie.pojo.Log"> insert into log values(default,#{accOut},#{accIn},#{money}) </insert> </mapper> ``` ## yan.ibbie.pojo.log如下 ``` package yan.ibbie.pojo; public class Log { private int id; private String accOut; private String accIn; private double money; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getAccOut() { return accOut; } public void setAccOut(String accOut) { this.accOut = accOut; } public String getAccIn() { return accIn; } public void setAccIn(String accIn) { this.accIn = accIn; } public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } } ``` ## AccountServiceImpl如下: ``` package yan.ibbie.service.Impl; import java.io.IOException; import java.io.InputStream; import java.util.Date; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import com.sun.istack.internal.logging.Logger; import yan.ibbie.pojo.Account; import yan.ibbie.pojo.Log; import yan.ibbie.service.AccountService; public class AccountServiceImpl implements AccountService { @Override public int transfer(Account accIn, Account accOut) throws IOException { InputStream is = Resources.getResourceAsStream("mybatis.xml"); SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is); SqlSession session = factory.openSession(); Account accOutSelect = session.selectOne("yan.ibbie.mapper.accountmapper.selByAccnoPassword",accOut); if (accOutSelect!=null) { if(accOutSelect.getBalance()>=accOut.getBalance()) { Account accInSelect = session.selectOne("yan.ibbie.mapper.accountmapper.selByAccnoName",accIn); if (accInSelect!=null) { accIn.setBalance(accOut.getBalance()); accOut.setBalance(-accOut.getBalance()); int index=session.update("yan.ibbie.mapper.accountmapper.updBalanceByAccno", accOut); index += session.update("yan.ibbie.mapper.accountmapper.updBalanceByAccno",accIn); if (index==2) { Log log = new Log(); log.setAccOut(accOut.getAccNo()); log.setAccIn(accIn.getAccNo()); log.setMoney(accIn.getBalance()); session.update("yan.ibbie.mapper.logmapper.insLog", log); Logger logger = Logger.getLogger(AccountServiceImpl.class); logger.info(log.getAccOut()+"给"+log.getAccIn()+ "在"+new Date().toLocaleString()+"转了"+log.getMoney()); session.commit(); session.close(); return SUCCESS; }else { session.rollback(); session.close(); return ERROR; } }else { return ACCOUNT_NAME_NOT_MATCH; } }else { return ACCOUNT_BALANCE_NOT_ENOUGHT; } }else { return ACCOUNT_PASSWORD_NOT_MATCH; } } } ```
相见恨晚的超实用网站
相见恨晚的超实用网站 持续更新中。。。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 free -m 其中:m表示兆,也可以用g,注意都要小写 Men:表示物理内存统计 total:表示物理内存总数(total=used+free) use...
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
python 简易微信实现(注册登录+数据库存储+聊天+GUI+文件传输)
socket+tkinter详解+简易微信实现 历经多天的努力,查阅了许多大佬的博客后终于实现了一个简易的微信O(∩_∩)O~~ 简易数据库的实现 使用pands+CSV实现数据库框架搭建 import socket import threading from pandas import * import pymysql import csv # 创建DataFrame对象 # 存储用户数据的表(...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发...
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 演示地点演示 html代码如下` music 这个年纪 七月的风 音乐 ` 然后就是css`*{ margin: 0; padding: 0; text-decoration: none; list-...
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。
数据库优化 - SQL优化
以实际SQL入手,带你一步一步走上SQL优化之路!
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小型人工智障。 知识可以运用在不同地方,不一定非是天气预报。
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹...
面试官:你连RESTful都不知道我怎么敢要你?
干货,2019 RESTful最贱实践
刷了几千道算法题,这些我私藏的刷题网站都在这里了!
遥想当年,机缘巧合入了 ACM 的坑,周边巨擘林立,从此过上了"天天被虐似死狗"的生活… 然而我是谁,我可是死狗中的战斗鸡,智力不够那刷题来凑,开始了夜以继日哼哧哼哧刷题的日子,从此"读题与提交齐飞, AC 与 WA 一色 ",我惊喜的发现被题虐既刺激又有快感,那一刻我泪流满面。这么好的事儿作为一个正直的人绝不能自己独享,经过激烈的颅内斗争,我决定把我私藏的十几个 T 的,阿不,十几个刷题网...
JavaScript 为什么能活到现在?
作者 | 司徒正美 责编 |郭芮 出品 | CSDN(ID:CSDNnews) JavaScript能发展到现在的程度已经经历不少的坎坷,早产带来的某些缺陷是永久性的,因此浏览器才有禁用JavaScript的选项。甚至在jQuery时代有人问出这样的问题,jQuery与JavaScript哪个快?在Babel.js出来之前,发明一门全新的语言代码代替JavaScript...
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
Nginx 原理和架构
Nginx 是一个免费的,开源的,高性能的 HTTP 服务器和反向代理,以及 IMAP / POP3 代理服务器。Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求,主要负责调度工作进程:加载配置、启动工作进程及非停升级。worker 进程负责处...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
Python 编程开发 实用经验和技巧
Python是一门很灵活的语言,也有很多实用的方法,有时候实现一个功能可以用多种方法实现,我这里总结了一些常用的方法和技巧,包括小数保留指定位小数、判断变量的数据类型、类方法@classmethod、制表符中文对齐、遍历字典、datetime.timedelta的使用等,会持续更新......
吐血推荐珍藏的Visual Studio Code插件
作为一名Java工程师,由于工作需要,最近一个月一直在写NodeJS,这种经历可以说是一部辛酸史了。好在有神器Visual Studio Code陪伴,让我的这段经历没有更加困难。眼看这段经历要告一段落了,今天就来给大家分享一下我常用的一些VSC的插件。 VSC的插件安装方法很简单,只需要点击左侧最下方的插件栏选项,然后就可以搜索你想要的插件了。 下面我们进入正题 Material Theme ...
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
开源并不是你认为的那些事
点击上方蓝字 关注我们开源之道导读所以 ————想要理清开源是什么?先要厘清开源不是什么,名正言顺是句中国的古代成语,概念本身的理解非常之重要。大部分生物多样性的起源,...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
Python 植物大战僵尸代码实现(2):植物卡片选择和种植
这篇文章要介绍的是: - 上方植物卡片栏的实现。 - 点击植物卡片,鼠标切换为植物图片。 - 鼠标移动时,判断当前在哪个方格中,并显示半透明的植物作为提示。
相关热词 c# 引用mysql c#动态加载非托管dll c# 两个表数据同步 c# 返回浮点json c# imap 链接状态 c# 漂亮字 c# 上取整 除法 c#substring c#中延时关闭 c#线段拖拉
立即提问