<%@ page import="java.sql.*"%>
<html>
<body>
<%
String url = "jdbc:mysql://localhost/javaicq?user=&password=&useUnicode=true&characterEncoding=8859_1"; try{
System.out.println("1111111111111111111111111111111111");
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("2222222222222222222222222222222222");
Connection conn= DriverManager.getConnection(url);
System.out.println("3333333333333333333333333333333333");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
System.out.println("4444444444444444444444444444444444");
String sql="select * from icq";
ResultSet rs=stmt.executeQuery(sql);
System.out.println("5555555555555555555555555555555555");
while(rs.next()) {%>
First content:<%=rs.getString(5)%>
Second content:<%=rs.getString(9)%>
<%}%>
<%System.out.print("Successfully!!!!");%>
<%rs.close();
stmt.close();
conn.close();
}catch(Exception ex){}
%></body>
</html>
在用mysql我好像没有设置什么端口。
修改user pwd 是在mysql命令模式下的修改命令。可以试一试!
<html>
<body>
<%
String url = "jdbc:mysql://localhost/javaicq?user=&password=&useUnicode=true&characterEncoding=8859_1"; try{
System.out.println("1111111111111111111111111111111111");
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("2222222222222222222222222222222222");
Connection conn= DriverManager.getConnection(url);
System.out.println("3333333333333333333333333333333333");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
System.out.println("4444444444444444444444444444444444");
String sql="select * from icq";
ResultSet rs=stmt.executeQuery(sql);
System.out.println("5555555555555555555555555555555555");
while(rs.next()) {%>
First content:<%=rs.getString(5)%>
Second content:<%=rs.getString(9)%>
<%}%>
<%System.out.print("Successfully!!!!");%>
<%rs.close();
stmt.close();
conn.close();
}catch(Exception ex){}
%></body>
</html>
在用mysql我好像没有设置什么端口。
修改user pwd 是在mysql命令模式下的修改命令。可以试一试!
解决方案 »
- 关于css样式
- 如何循环读取mysql数据库中一个表的多个字段的值.
- 哪位帮我看看这个页面到底哪里有问题,无法再浏览器显示,眼都瞪晕了
- 关于hibernate配置文件中,hibernate.hbm2ddl.auto值的设置?
- ibatis动态字段不显示?
- 如何将字符型转换成int型
- 如何得到<select>里的内容~~~~~~~~~~~~~~~~~~~~~~~~~~
- 关于JSP中的request.getparameter(String: )String的提问
- 请问servlet在tomcat4.1中如何编译?
- java mail imap 保存附件问题
- 一个简单的msn问题
- 问一个有关设计的问题(欢迎大家进入提供意见,入者有分)
public static void main(String[] args) {
try {
// The newInstance() call is a work around for some
// broken Java implementations Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
}
before you run the program you must open of run the mysql sever first
see the http://dev.mysql.com/doc/connector/j/en for more details
public class ConnectMySql{
public static void main(String args[]){
String driver="org.gjt.mm.mqsql.Driver";
String url="jdbc:mysql://leo:3306/jxgl";
String user="leo";
String password="";
Connection con=null;
try{
Class.forName(driver);
}
catch(Exception e){
System.out.println("Driver cannot be loaded!");
}
try{
con=DriverManager.getConnection(url,user,password);
if(con!=null)
System.out.println("数据连接成功");
}
catch(SQLException ee){
System.out.println("数据连接失败");
}
} if(con!=null){
con.close();
}
}
错了阿~~~!!!
url="jdbc:mysql://localhost://3306/database_name";
String user="yourname"; String password="";
Connection con=DriverManager.getConnection(url,user,password);
或者:
url="jdbc:mysql://localhost://3306/database_name?user=Leo?password=";
Connection con=DriverManager.getConnection(url);
都可以的
con.close();
}
应该提上一个括号里去