package sql;import javax.swing.JOptionPane;
import java.sql.*;
import java.awt.*;public class OneDeath2 {
public static void main(String[] args) { try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
conn =DriverManager.getConnection("jdbc:microsoft:sqlserver://222.129.68.152;DatabaseName=chris","sa","");
stmt = conn.createStatement(); String Sno1 = JOptionPane.showInputDialog("请输入学号");
String Sn1 = JOptionPane.showInputDialog("请输入姓名");
String age1 = JOptionPane.showInputDialog("请输入年龄"); rs = stmt.executeQuery("insert into student(sno) values('"+Sno1+"')");
rs1 = stmt.executeQuery("insert into student(sn) values('"+Sn1+"')");
rs2 = stmt.executeQuery("insert into student(age) values('"+age1+"')");}
catch(Exception e){
e.printStackTrace();
}}
}感觉没什么问题,但是报错:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
atcom.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
at sql.OneDeath2.main(OneDeath2.java:27)
import java.sql.*;
import java.awt.*;public class OneDeath2 {
public static void main(String[] args) { try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
conn =DriverManager.getConnection("jdbc:microsoft:sqlserver://222.129.68.152;DatabaseName=chris","sa","");
stmt = conn.createStatement(); String Sno1 = JOptionPane.showInputDialog("请输入学号");
String Sn1 = JOptionPane.showInputDialog("请输入姓名");
String age1 = JOptionPane.showInputDialog("请输入年龄"); rs = stmt.executeQuery("insert into student(sno) values('"+Sno1+"')");
rs1 = stmt.executeQuery("insert into student(sn) values('"+Sn1+"')");
rs2 = stmt.executeQuery("insert into student(age) values('"+age1+"')");}
catch(Exception e){
e.printStackTrace();
}}
}感觉没什么问题,但是报错:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
atcom.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
at sql.OneDeath2.main(OneDeath2.java:27)
解决方案 »
- 大家来帮我看看这个下标越界的问题,搞的有点累
- 一道JAVA递归算法的编程题
- 问个问题,我准备j2ee方向,我还用学一下swing不了?
- 请帮帮我
- 关于Excel数据的导出
- 有什么java api 是和矢量图相关的吗?
- 初学者,在tomcat 下运行jsp的问题,那位朋友能帮帮我。在网上看了一大堆资料,也无法成功配置,解决后另加100分
- 怎样通过代码选中JTable中的一行?
- 请教,jdbc的连接串中怎么带上sqlserver的实例名称?(急死我了)
- 请问在java钟如何得到数据库中的记录总数,以及如何求数据库中一个字段的和?
- 请各位大师赶紧帮忙
- @@@@@@@@@@@@@@@高手帮帮我好白!!@@@@@@@@@@@@@@@@@@
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
这个可以删了.因为这个是查询用的。把rs再设置成int或者String型的.
executeQuery这个方法是查询用的,应该改成executeUpdate