import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;

import com.mysql.jdbc.Driver;

public class Sqltest {

private final static String DRIVER="com.mysql.jdbc.Driver";
private final static String URL = "jdbc:mysql://127.0.0.1:3306/signin";
private final static String USERNAME = "root";
private final static String PASSWORD = "21424019";
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Driver driver = (Driver)Class.forName(DRIVER).newInstance();
DriverManager.registerDriver(driver);
Connection con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
con.setAutoCommit(false);
//String sql="select user_id from `test`.`new_table` where user_id=";
String sql="insert into test.new_table(user_id,password) values(?,?)";
String sql2=" and password=";
String user_id1="harry1",password1="123456";
String user_id2="'potter1' or '1'='1'--";
String password2="'23456790'";
StringBuffer sb=new StringBuffer();
sb.append(sql);
sb.append(user_id1);
sb.append(sql2);
sb.append(password1);
PreparedStatement preparestatement = con.prepareStatement(sql);
preparestatement.setString(1,user_id1);
preparestatement.setString(2, password1);
Savepoint svpt=con.setSavepoint();
int lines=preparestatement.executeUpdate();
if(lines>=1)
{
System.out.println(lines);
con.rollback();
//con.rollback(svpt);
}

con.commit();

con.releaseSavepoint(svpt);
/*Statement statement = con.createStatement();
System.out.println("sql: "+sb.toString());
ResultSet result= statement.executeQuery(sb.toString());
while(result.next())
{
System.out.println("USER_ID1");
System.out.println(result.getString(1));
}
sb.setLength(0);
sb.append(sql);
sb.append(user_id2);
sb.append(sql2);
sb.append(password2);
ResultSet result2 = statement.executeQuery(sb.toString());
while(result2.next())
{
System.out.println("USER_ID2");
System.out.println(result2.getString(1));
}*/
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

java sql的更多相关文章

  1. Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Lock wait timeout exceeded; try restarting transaction

    更新的时候报 Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Loc ...

  2. '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error

    '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error 异常现象 ### Cause: java.sql.SQ ...

  3. java.sql.Connection解决插入数据库中文乱码问题

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public clas ...

  4. java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to repair it

    java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to re ...

  5. mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

    同步发布:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html 在使用mysql时,如果数据库中的字段类型是timestamp,默认为 ...

  6. java.sql.SQLException: ORA-00911: invalid character 解决方法

    java.sql.SQLException: ORA-00911: invalid character 控制台抛出这个异常:java.sql.SQLException: ORA-00911: inva ...

  7. java.sql.SQLException: No suitable driver 问题解决

    最近在学习java,用到c3p0数据库连接池,遇到一个很奇怪的现象,用main方法测试是可以正常连接数据库的,但是使用jsp调用代码,就会报如下图的错误! 最下面的java.sql.SQLExcept ...

  8. java.sql.SQLException: JZ00L

    出现, java.sql.SQLException: JZ00L: 登录失败.检查与此异常现象有关的 SQL 警告以获得失败原因. at com.sybase.jdbc3.jdbc.ErrorMess ...

  9. Type mismatch: cannot convert from java.sql.PreparedStatement to com.mysql.jdbc.PreparedStatement

    Connection.prepareStatement()函数出错,提示: Type mismatch: cannot convert from java.sql.PreparedStatement ...

  10. java.util.Date与java.sql.Date

    我数据库里用到了日期类型.用java编程的时候同时import了java.util.*和java.sql.*,发现直接申明Date类型 Date dt; 会报错,查了一下才发现有java.util.D ...

随机推荐

  1. 运行时动态库:not found 及介绍-linux的-Wl,-rpath命令

    ---此文章同步自我的CSDN博客--- 一.运行时动态库:not found   今天在使用linux编写c/c++程序时,需要用到第三方的动态库文件.刚开始编译完后,运行提示找不到动态库文件.我就 ...

  2. Android APP 性能优化的一些思考

    说到 Android 系统手机,大部分人的印象是用了一段时间就变得有点卡顿,有些程序在运行期间莫名其妙的出现崩溃,打开系统文件夹一看,发现多了很多文件,然后用手机管家 APP 不断地进行清理优化 ,才 ...

  3. ESLint 的正式使用感受

    介绍ESLint ESLint 是一个代码规范和错误检查工具,有以下几个特性 所有东西都是可以插拔的.你可以调用任意的rule api或者formatter api 去打包或者定义rule or fo ...

  4. Dubbo源码学习--服务发布(ProxyFactory、Invoker)

    上文分析了Dubbo服务发布的整体流程,但服务代理生成的具体细节介绍得还不是很详细.下面将会接着上文继续分析.上文介绍了服务代理生成的切入点,如下: Invoker<?> invoker ...

  5. SQL Server学习之路(六):“增删改查”之“查”

    0.目录 1.前言 2.最基本的SQL查询语句 3.select...from... 3.1 "*"与"Top num *" 3.2 查询指定列 3.3 Isn ...

  6. LintCode-落单的数 III

    给出2*n + 2个的数字.除当中两个数字之外其它每一个数字均出现两次,找到这两个数字. 您在真实的面试中是否遇到过这个题? Yes 例子 给出 [1,2,2,3,4,4,5,3].返回 1和5 挑战 ...

  7. NBUT 1217 Dinner

    [1217] Dinner 时间限制: 1000 ms 内存限制: 32768 K 问题描写叙述 Little A is one member of ACM team. He had just won ...

  8. Janus 二元神漏洞测试

    同步发表于:http://blog.hacktons.cn/2017/12/25/janus-demo/ 背景 12月9号,Andorid对外曝光了一个名为Janus的重量级系统漏洞CVE-2017- ...

  9. Python笔记·第七章—— IO(文件)处理

    一.文件处理简介 计算机系统分为:计算机硬件,操作系统,应用程序三部分. 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件,众所周知 ...

  10. 翻译:Identifier Qualifiers标识限定符

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...