mysql
连接数据库的代码怎么写
连接数据库的代码怎么写
2016-02-21
JSP中用<%@ include file="conn1.jsp"%>连接到conn1文件,通过conn1连接到数据库,conn1代码如下:
<%@ page import="java.sql.*"%> <% String dbDriver="com.mysql.jdbc.Driver"; String server="localhost"; String dbname="experiment"; String user="root"; String pass="0000"; String port="3306"; String url="jdbc:mysql://"+server+":"+port+"/"+dbname+"?user="+user+"&password="+pass+"&useUnicode=true&characterEncoding=gbk"; Class.forName(dbDriver); Connection conn= DriverManager.getConnection(url); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql; ResultSet rs; %>
举报