public static void main(String[] args) {
Connection conn = null
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
String dburl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)}DBQ=D:\\project\\Core_Java\\db\\yxbdata.mdb"//此为NO-DSN方式
//String dburl ="jdbc:odbc:odbcName"//此为ODBC连接方式
conn = DriverManager.getConnection(dburl)
Statement stmt=conn.createStatement()
// stmt.executeUpdate("insert into class(classid,classname) values(4,'arthurs')")
// ResultSet rs=stmt.executeQuery("select Top 20 * from MobileSection")
ResultSet rs=stmt.executeQuery("select * from class")
while(rs.next()){
System.out.println(rs.getString("classId")+","+rs.getString("classname"))
}
} catch (Exception e) {
e.printStackTrace()
}finally{
try {
if(conn != null){
conn.close()
}
} catch (SQLException e) {
e.printStackTrace()
}
}
==========================
mysql
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
String text = ""
String url = "jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=gbk"
Class.forName("org.gjt.mm.mysql.Driver").newInstance()
Connection conn = (Connection) DriverManager.getConnection(url)
Statement stmt = (Statement) conn.createStatement()
ResultSet rs = stmt.executeQuery("select * from hjx where id=26")
while(rs.next()){
text = rs.getString("text")
}
System.out.println(MysqlToMysql.changeYinHao(text))
conn.close()
}
==============================
mssql
public static void getText() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
String url = "jdbc:microsoft:sqlserver://localhost:1433DatabaseName=成绩查询"
String name ="sa"String pwd = "sa"
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance()
// Connection conn = (Connection) DriverManager.getConnection(url,name,pwd)
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433databasename=成绩查询","sa","sa")
conn.setAutoCommit(false)
Statement stmt = conn.createStatement()
// PreparedStatement stmt = (PreparedStatement) conn.prepareStatement("select top 10 * from employee")
ResultSet rs = stmt.executeQuery("select top 10 * from employee")
while(rs.next()){
System.out.println(rs.getString("name")+"-"+rs.getString("department"))
//log.debug(rs.getString("name")+"-"+rs.getString("Address"))
}
conn.commit()
}
public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
ConnMSSql.getText()
}
mysql -u root -p。这是另外一种通过命令提示符窗口连接MySQL,就是我们常用的cmd命令提示符窗口。
在命令提示符窗口中输入mysql -u root -p,然后输入密码就可以连接到数据库。进入mysql环境后,就可以执行相关命令,像select、create这些语法都是可以执行。
另外一种MySQL安装,双击软件后d出界面,点击Next下一步。然后接受协议,点击Next下一步。选择Typical典型的,安装通用功能就可以,这里选中后会直接跳到下一个页面。点击Install,开始安装。如果Install旁边有类似防火墙的标志,需要在d出的窗中点击“是”。等待安装,需要一点时间,请耐心等待。安装成功后,进入MySQL介绍页面,点击Next。
选中CheckBox,然后点击Finish。这里会有个提示窗,点击“是”就行。进入MySQL配置页面,点击Next。保持默认设置就可以,点击Next下一步。保持默认配置,继续Next下一步。继续保持默认配置,点击Next下一步。继续保持默认配置,点击Next下一步。继续保持默认配置,点击Next下一步。保持默认配置,点击Next下一步。
自定义字符编码,选中utf8,然后点击Next。添加一个命令符窗口,然后点击Next。设置MySQL数据库密码,选中CheckBox,允许远程访问,然后点击Next。准备执行配置,点击Execute按钮。点击Finish,大功告成。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)