有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从销售点Mysql数据库读取特定信息

我叫奥马尔, 我在windows中有一个销售点程序,我必须使用Java获取特定的数据。 销售点使用mysql作为数据库,在数据库结构中,它创建了一个名为“it”的数据库,其中包含许多表。 我想获取一个名为Ticketid的字段数据

该程序不安装mysql。c单元中的exe,它使用一个名为mysqld的程序。exe位于销售点文件夹中,以便使用数据库。 为了使用命令提示符查看“iTPV”数据库,我必须进入“iTPV”程序的特定\bin文件夹并运行mysqld。然后运行mysql。在命令提示符下,我使用mysql-u root-p作为exe,应用密码,然后成功进入。 为了获取“Ticketid”字段,我创建了一个java程序,但没有成功,可能是“String myUrl”中出现了问题。 在应用这个程序之前,我使用mysqld。在一个命令提示符窗口和另一个命令提示符窗口中,我应用java程序,但没有成功,结果如下

有个例外! 通用域名格式。mysql。jdbc。司机

java程序是这样的

import java.sql.*;



/**
 * A Java MySQL SELECT statement example. Demonstrates the use of a SQL
 * SELECT statement against a MySQL database, called from a Java program.
 *
 *
 */
public class calculadora {

    public static void main(String[] args) {
        try {
            // create our mysql database connection

            String myDriver = "com.mysql.jdbc.Driver";

            String myUrl = "jdbc:mysql://localhost:3336/itpv";
            String user = "root";

            String password = "***************";

            Class.forName(myDriver);

            Connection con = DriverManager.getConnection(myUrl, user, password);
            //Connection conn = DriverManager.getConnection(myUrl, "root", "");

            // our SQL SELECT query. 
            // if you only need a few columns, specify them by name instead of using "*"
            String query = "SELECT * FROM tickets";

            // create the java statement
            Statement st = con.createStatement();

            // execute the query, and get a java resultset
            ResultSet rs = st.executeQuery(query);

            // iterate through the java resultset
            while (rs.next()) {

                int TICKid = rs.getInt("TICKETID");

                // print the results
                // System.out.format("%s, %s, %s, %s, %s, %s\n", id, firstName, lastName, dateCreated, isAdmin, numPoints);
                System.out.format("%s\n", TICKid);
            }
            st.close();
        } catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());
        }
    }
}

问题似乎是mysql与数据库的连接问题, 密码正确,程序结构也正确。 也许我不能很好地定位“String myUrl”地址,在基于mysql数据库的命令提示符中是否有方法获取数据库的String myUrl的正确位置?,mysqld的目的是什么。exe?,提前谢谢你,谢谢你的帮助

奥马尔·托雷斯


共 (2) 个答案

  1. # 1 楼答案

    ?Estás seguro de que拥有datos com基地的指挥系统。mysql。jdbc。司机

    ?您确定已正确加载关系数据库管理系统com的驱动程序。mysql。jdbc。司机

  2. # 2 楼答案

    is there a way inside mysql databased command prompt to acquire the correct location of String myUrl of a database?

    否,因为Java所需的URL是特定于jdbc驱动程序的

    what is the purpose of mysqld.exe?

    这是服务器进程。当java程序需要在数据库中放入某些内容或询问数据库中有什么内容时,它应该在后台运行,它将要求该程序执行此操作。使用服务器允许多个程序共享相同的数据

    可能的问题

    mysql的默认端口是3306,您的端口设置为3336,这可能是输入错误。尽管端口可以重新配置