JDBC要怎么设置才能和MYSQL数据库连接?? mysql有自己本身的驱动程序,直接加载后就能访问数据库了,不是一定需要jdbc 的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //@author:Andy//@version:1.0//function:query data from databse coffeebreak,TABLE COFFEESimport java.sql.*;public class Query{ public static void main(String [] args) { String url = "jdbc:mysql://localhost/coffeebreak"; Connection con; Statement stmt; String qu = "select COF_NAME, PRICE from coffees where PRICE<9.0"; try { Class.forName("com.mysql.jdbc.Driver");//看起来虽然不顺眼,但是可以支持中文 } catch(ClassNotFoundException e) { System.err.println("Class Not Found!"); System.err.println("e.getMessage()"); } try { con = DriverManager.getConnection(url,"root",""); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(qu); System.out.println("Coffee Break Coffees and Prices:"); while(rs.next()) { String name = rs.getString("COF_NAME"); float price = rs.getFloat("PRICE"); System.out.println("Coffee Name: "+name+" Price: "+price); } } catch(SQLException e) { System.err.println("SQLException:"+e.getMessage()); }}} http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" 前提是你有JDBC驱动.... 驱动程序怎么安装.CLASSPATH怎么设置??? 求助:java如何操作windows日志文件 关于延时显示的问题 用java实现随机选择按钮 jfreeChart纵坐标轴问题 hi,大家好。编译错误:需要为 '(' 或 '[' 是什么原因? 如何去掉string里的回车 大家用啥来建模? jdk中容器源码的疑惑,难道是多余的么 如何在redhat9.0中安装jdk 广播:::谁有Jbuilder3.5的注册马? JAVA里没有指针,它有引用,但是指针和引用有什么区别,不都是地址吗 关于swing滚动条的问题~~大家多帮帮忙哦!:)
//@version:1.0
//function:query data from databse coffeebreak,TABLE COFFEES
import java.sql.*;
public class Query
{
public static void main(String [] args)
{
String url = "jdbc:mysql://localhost/coffeebreak";
Connection con;
Statement stmt;
String qu = "select COF_NAME, PRICE from coffees where PRICE<9.0";
try
{
Class.forName("com.mysql.jdbc.Driver");//看起来虽然不顺眼,但是可以支持中文
}
catch(ClassNotFoundException e)
{
System.err.println("Class Not Found!");
System.err.println("e.getMessage()");
}
try
{
con = DriverManager.getConnection(url,"root","");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(qu);
System.out.println("Coffee Break Coffees and Prices:");
while(rs.next())
{
String name = rs.getString("COF_NAME");
float price = rs.getFloat("PRICE");
System.out.println("Coffee Name: "+name+" Price: "+price);
}
}
catch(SQLException e)
{
System.err.println("SQLException:"+e.getMessage());
}
}
}