向SQL插入数据是怎么插啊?
我插进去了 但老是有异常 说:java.sql.SQLException: No ResultSet set was produced.
部分代码如下import java.sql.*;class DataBase
{
String name;
String psw;
int age;
String sex;
String email;
public DataBase db = null;
private Connection con = null;
private Statement st = null;
public ResultSet rs = null;
//public ResultSet rsp = null;
public DataBase() throws Exception
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DataBase","sa","yuanfujie");
st = con.createStatement();
}
public boolean insert(String n,String p,int a,String s,String e) throws Exception
{
rs = st.executeQuery("insert into Login values('" + n + "','" + p + "','" + a + "','" + s + "','" + e +"')");
}
public static void main(String[] g) throws Exception
{
DataBase db = new DataBase();
}
}
我插进去了 但老是有异常 说:java.sql.SQLException: No ResultSet set was produced.
部分代码如下import java.sql.*;class DataBase
{
String name;
String psw;
int age;
String sex;
String email;
public DataBase db = null;
private Connection con = null;
private Statement st = null;
public ResultSet rs = null;
//public ResultSet rsp = null;
public DataBase() throws Exception
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DataBase","sa","yuanfujie");
st = con.createStatement();
}
public boolean insert(String n,String p,int a,String s,String e) throws Exception
{
rs = st.executeQuery("insert into Login values('" + n + "','" + p + "','" + a + "','" + s + "','" + e +"')");
}
public static void main(String[] g) throws Exception
{
DataBase db = new DataBase();
}
}
解决方案 »
- eclipse报黄是不是不能产生可执行的jar文件
- 请问如何设定当前写入目录?
- 求助,高手来说详细点!
- dateoutputstream和dateinputstream怎么用
- 关于JAVA的输入/输出流问题(初学者)
- 接口操作的问题
- System.out.println(ghyghost_Boolean.hashCode());得出的数字是什么意思?
- 谁用过rowset的CachedRowSet
- JBuilder 2005
- 急!!高手们,请问Vector、ArrayList和List的异同!
- ACM contest 大学生程序设计竞赛 Question 4 求解!!!
- JAVA连接SQL2005的问题
public boolean insert(String n,String p,int a,String s,String e) throws Exception
{
rs = st.executeQuery("insert into Login values('" + n + "','" + p + "','" + a + "','" + s + "','" + e +"')");
}
有问题.进行插入或修改操作时使用的是 executeUpdate方法.
比如:
stmt.executeUpdate(sql);