package com.hu.demo
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement
import java.sql.SQLException
public class DBHelper {
public static final String url = "jdbc:mysql://127.0.0.1/student"
public static final String name = "com.mysql.jdbc.Driver"
public static final String user = "root"
public static final String password = "root"
public Connection conn = null
public PreparedStatement pst = null
public DBHelper(String sql) {
try {
Class.forName(name)//指定连接类型
conn = DriverManager.getConnection(url, user, password)//获取连接
pst = conn.prepareStatement(sql)//准备执行语句
} catch (Exception e) {
e.printStackTrace()
}
}
public void close() {
try {
this.conn.close()
this.pst.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
}
SQL库的连接方式'Conn_String="Provider=SQLOLEDBData Source=.Initial Catalog=dataUser ID=saPassword="
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open Conn_String
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)