当前位置: 技术问答>java相关
450,我全部的分急求java应用程序操作mysql数据库的例子
来源: 互联网 发布时间:2015-08-18
本文导语: 我要开发一个进销存软件,决定采用mysql数据库,不知谁有开发java应用程序操作mysql数据库的例子 我目前共有455分,其它300分由于没人能解决问题而都没有散。谁如果能回答这个问题,我可以把分全给你,只要你去...
我要开发一个进销存软件,决定采用mysql数据库,不知谁有开发java应用程序操作mysql数据库的例子
我目前共有455分,其它300分由于没人能解决问题而都没有散。谁如果能回答这个问题,我可以把分全给你,只要你去各个链接点一下即可!
我目前共有455分,其它300分由于没人能解决问题而都没有散。谁如果能回答这个问题,我可以把分全给你,只要你去各个链接点一下即可!
|
import java.awt.*;
import java.sql.*;
public class Linkdb {
// String strDriver="com.codestudio.sql.PoolMan";
String strDriver="org.gjt.mm.mysql.Driver";
//String strConn="jdbc:poolman://";
String strConn="";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public Linkdb() {
//连接MySql_jdbc驱动程序
try {
Class.forName(strDriver).newInstance();
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
}
//执行Select语句
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
return rs;
}
//执行Insert,Update语句
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
}
public boolean checkrepeatuser(String username) {
stmt = null;
rs=null;
int i=0;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
CodeTransfer codetransfer=new CodeTransfer();
String Strsql="select ID from user where Alias='" + username + "'";
System.out.println(Strsql);
rs=stmt.executeQuery(Strsql);
while(rs.next()){
i++;
}
stmt.close();
conn.close();
}catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
if(i>0)
return false;
else
return true;
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
把分给我
import java.sql.*;
public class Linkdb {
// String strDriver="com.codestudio.sql.PoolMan";
String strDriver="org.gjt.mm.mysql.Driver";
//String strConn="jdbc:poolman://";
String strConn="";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public Linkdb() {
//连接MySql_jdbc驱动程序
try {
Class.forName(strDriver).newInstance();
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
}
//执行Select语句
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
return rs;
}
//执行Insert,Update语句
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
}
public boolean checkrepeatuser(String username) {
stmt = null;
rs=null;
int i=0;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
CodeTransfer codetransfer=new CodeTransfer();
String Strsql="select ID from user where Alias='" + username + "'";
System.out.println(Strsql);
rs=stmt.executeQuery(Strsql);
while(rs.next()){
i++;
}
stmt.close();
conn.close();
}catch (Exception E) {
System.err.println("==> SQLException: ");
while (E!= null) {
System.out.println("Message: " + E.getMessage ());
}
}
if(i>0)
return false;
else
return true;
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
把分给我
|
我有一个,shareMySQLAdmin
你可以在我的主页下载,如果需要源码,友情交换。
http://www.sharetop.com
你可以在我的主页下载,如果需要源码,友情交换。
http://www.sharetop.com