怎样用myeclipse实现一个对数据库中的数据添加的操作
1个回答
展开全部
package com.ytj.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Create {
private Connection conn;
private Statement stmt;
private ResultSet rs;
String sql="insert into register(name,password)values('z','123')";
public void SqlConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
ex.printStackTrace();
}
String url="jdbc:odbc:fred";
try{
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void Register(){
rs=stmt.executeQuery("insert into register(name,password)values('"+name+"','"+password+"')");
}public void Close()throws Exception{
rs.close();
stmt.close();
conn.close();
}
public void main() throws Exception{
Create create=new Create();
create.SqlConnection();
create.Register();
create.Close();
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Create {
private Connection conn;
private Statement stmt;
private ResultSet rs;
String sql="insert into register(name,password)values('z','123')";
public void SqlConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
ex.printStackTrace();
}
String url="jdbc:odbc:fred";
try{
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void Register(){
rs=stmt.executeQuery("insert into register(name,password)values('"+name+"','"+password+"')");
}public void Close()throws Exception{
rs.close();
stmt.close();
conn.close();
}
public void main() throws Exception{
Create create=new Create();
create.SqlConnection();
create.Register();
create.Close();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |