i have two tables
CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(20) NOT NULL AUTO_INCREMENT, `ud_id` varchar(50) NOT NULL, `name` text NOT NULL, `password` text NOT NULL, `email` varchar(200) NOT NULL, `image` varchar(150) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB
and mycatch table is
CREATE TABLE IF NOT EXISTS `mycatch` ( `catch_id` int(11) NOT NULL AUTO_INCREMENT, `catch_name` text NOT NULL, `catch_details` text NOT NULL, `longitude` float(10,6) NOT NULL, `latitude` float(10,6) NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON …
地址文本框中有单引号和双引号.如何插入数据库.我正在使用SQL2005.我的代码如下......
str = "exec sp_cust_reg '" + customer.Cust_Id + "','" + customer.Cust_Name + "','" + customer.Gender + "','" + customer.Acc_no + "','" + customer.Address + "','" + customer.Pin_no + "','" + customer.Phone_no + "','" + customer.Mobile_no + "','" + customer.Email + "','" + customer.Authorise + "'";
Run Code Online (Sandbox Code Playgroud)
地址是jo"hn's house
它的Text Visualizer如下......
exec sp_cust_reg 'C7','George Joseph','Male','0001-212123','jo"hn's house','515151','04862787896','8888888888','johnyqw@gmail.com','N'
Run Code Online (Sandbox Code Playgroud)
我用了
string sql = str.Replace("\'", " ");.
Run Code Online (Sandbox Code Playgroud)
然后我明白了
exec sp_cust_reg C7 , George Joseph , Male , 0001-212123 , jo"hn s house , 515151 , …
Run Code Online (Sandbox Code Playgroud) 我需要将行的值转换为列 - 例如:
SELECT s.section_name,
s.section_value
FROM tbl_sections s
Run Code Online (Sandbox Code Playgroud)
这个输出:
section_name section_value
-----------------------------
sectionI One
sectionII Two
sectionIII Three
Run Code Online (Sandbox Code Playgroud)
期望的输出:
sectionI sectionII sectionIII
-----------------------------------------
One Two Three
Run Code Online (Sandbox Code Playgroud) 我的堆栈跟踪:
cbs.ui.OverallReportUI btnGenerateBillActionPerformed
SEVERE: null
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at cbs.ui.OverallReportUI.GenerateReport(OverallReportUI.java:219)
at cbs.ui.OverallReportUI.btnGenerateBillActionPerformed(OverallReportUI.java:153)
at cbs.ui.OverallReportUI.access$100(OverallReportUI.java:38)
at cbs.ui.OverallReportUI$2.actionPerformed(OverallReportUI.java:85)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at …
Run Code Online (Sandbox Code Playgroud) 我有一个带有col1的表A,带有数据的col2
col1 col2
-----------
1 x
2 x
3 x
1 y
2 y
3 y
4 y
1 z
2 z
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
col1 col2
-----------
1 x
2 x
3 x
4 x
1 y
2 y
3 y
4 y
1 z
2 z
3 z
4 z
Run Code Online (Sandbox Code Playgroud)
即使col2中的值不存在col1中的最大值,即'4',查询最多也应显示4.
您的SQL语法有错误; 检查与您的MySQL服务器版本对应的手册,以便在第1行的')'附近使用正确的语法
似乎无法解决此错误:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//It is a postback so check if it was by div click (NOT WORKING because the javascript isnt posting back)
string target = Request["__EVENTTARGET"];
if (target == "DivClicked")
{
string id = Request["__EVENTARGUMENT"];
//Call my delete function passing record id
using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
{
cn.Open();
using (OdbcCommand cmd = new OdbcCommand("DELETE FROM WallPosting WHERE idWallPosting="+id+")", cn))
{ …
Run Code Online (Sandbox Code Playgroud) SQL在大多数安装中都能正常工作.但是我在加拿大的Oracle安装有问题(可能的日期本地化问题?).
http://www.google.com/search?q=ORA-01830
我正在向生成SQL的专有处理器提供数据.我只提供数据.我希望获得的信息可以帮助我解决问题而不需要处理器的支持.