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怎么设置??? eclipse出问题了,急!! 急!!!高手请帮忙!!! 请问在哪里可以下载HP UX的java jdk? 动态生成复选框 取xml里的节点名字 200分求救初学者程序 大神进!如果不是我疏忽,这就是java String equals的bug! java map 数值排序问题 简单问题(极品菜鸟问题)下午就揭贴 WIN2000下面,JDK安装成功,但是变量定义为什么不行呢? 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());
}
}
}